作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基本上我是一个 Winforms 的人。学习 ASP.Net 和 MVC 并陷入了一个问题。
我有一个名为 Calculation
的页面。内容如下
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>About</h2>
<p>
<%: ViewData["Message"] %>
</p>
</asp:Content>
HomeController.cs
public ActionResult Calculation(int value)
{
ViewData["Message"] = String.Format("{0} when squared produces {1}", value, Models.Mathematics.Square(value));
return View();
}
我按下 ctrl+5
并到达了我的主页。单击计算页面并收到错误信息
The parameters dictionary contains a null entry for parameter 'value' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Calculation(Int32)' in 'MathSolution.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
我试过了http://localhost:3670/Home/Calculation/5
还有http://localhost:3670/Home/Calculation?value=5
。我仍然收到错误。我还尝试将 HttpPost
放在 HomeController.cs 中的 Calculation
方法上。
但是,如果在 HomeContoller.cs 文件计算方法中我为参数设置了默认值,则错误消失并且我始终获得默认值。
老实说,我的教程能够使它工作,但我不确定我的解决方案有什么问题。如果您需要更多信息,请告诉我。
最佳答案
最简单的解决方案,不一定是最好的:尝试将参数名称更改为“id”
public ActionResult Calculation(int id)
{
ViewData["Message"] = String.Format("{0} when squared produces {1}", id, Models.Mathematics.Square(id));
return View();
}
检查 this更准确的解释
关于c# - "The parameters dictionary contains a null entry..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16969889/
我是一名优秀的程序员,十分优秀!