我需要在 MVC 中乘以 2 个数字
这是代码
控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication17.Controllers
{
public class leetController : Controller
{
//
// GET: /leet/
public ActionResult Index()
{
decimal result = Decimal.Parse(Request["FirstNum"]) * Decimal.Parse(Request["Secondnum"]);
ViewBag.Result = result;
return View();
}
}
}
看法
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<div>
<form>
First number: <input type="value" id="FirstNum" value=""><br>
Second number: <input type="value" id="Secondnum" value=""><br>
<input type="submit" value="Arvuta">
<asp:Label ID="Label1" runat="server" Text="Vastus"></asp:Label>
@ViewBag.Result
</form>
</div>
</body>
</html>
我得到一个错误值不能为空。参数名称:我尝试运行代码时的字符串
当我运行代码和行十进制结果 = Decimal.Parse(Request["FirstNum"]) * Decimal.Parse(Request["Secondnum"]); 似乎有问题。