Basically I am a Winforms guy. Learning ASP.Net and MVC and stuck in a problem.
I have page with name Calculation
. Contents are as follows
<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();
}
I pressed ctrl+5
and reached my homepage. Clicked Calculation page and received an error as
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
I tried passing
http://localhost:3670/Home/Calculation/5
and also
http://localhost:3670/Home/Calculation?value=5
. I am still receiving error. I have also tried placing HttpPost
on my Calculation
method in HomeController.cs.
However, if in HomeContoller.cs file Calculation method I place a default value for parameter, then error disappears and I get the default value always.
To be honest, my tutorial is able to make it work but I am not sure whats wrong with my solution. Please let me know if you need any more info.