I have Model Class "Project", it has a "Model" property, type is String.
When I create a Action as below:
[HttpPost]
public ActionResult Create(Project model)
{
if (ModelState.IsValid)
{
// save model into database
}
return View(model);
}
Run this action , I found the parameter "model" in Create method is always null, and with exception is "Can't convert String into Project".
Then , I change this property from "Model" to "ModelNumber", everything is OK!
Comments: Thanks for reporting this issue. This is an unfortunate side effect of model binding. Your workaround is right, but since the scenario is not very common we chose to keep it as is.
When I create a Action as below:
[HttpPost]
public ActionResult Create(Project model)
{
if (ModelState.IsValid)
{
// save model into database
}
return View(model);
}
Run this action , I found the parameter "model" in Create method is always null, and with exception is "Can't convert String into Project".
Then , I change this property from "Model" to "ModelNumber", everything is OK!
Comments: Thanks for reporting this issue. This is an unfortunate side effect of model binding. Your workaround is right, but since the scenario is not very common we chose to keep it as is.