In this article I will
show you how you can set the default value to a controller post method
parameter in an mvc application. We always face some situation where we don’t need
to pass the parameter value but post back event take place. So in this case we
will get below mention error.
Some of my previous articles which you may like: Error
: SQL Server Compact is not intended for ASP.NET development., Bind
DropDownList Using Entity Framework in ASP.Net MVC Using C#,
Simple Login From in Asp.Net MVC Using C#.Net, Increase
Session TimeOut in MVC 4
The
parameters dictionary contains a null entry for parameter 'id' of
non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult
Index(Int32)' in 'PartialViewInMvc.Controllers.HomeController'. An optional
parameter must be a reference type, a nullable type, or be declared as an
optional parameter.
Parameter
name: parameters
|
So the get method with no parameter.
[HttpGet]
public ActionResult Index()
{
return
View();
}
|
Now httpost method with default parameter value.
[HttpPost]
public ActionResult Index(int
id=0)
{
return
View();
}
|
Enjoy the code. Happy coding J
0 comments:
Please let me know your view