问题
I have an action where the request is being generated from a kendo ui grid's Create event. The information is all being posted correctly, and the model binder works properly expect in any case where the action parameter name is 'model'
If the action is defined like this:
[HttpPost]
public ActionResult Create(ModelType post)
{
}
Everything works properly.
If instead though, the action looks like this:
[HttpPost]
public ActionResult Create(ModelType model) //changed parameter Name to model
{
}
I get an invalid model state and this message:
System.Web.Mvc.ModelError
The parameter conversion from type 'System.String' to type 'MyApp.Common.Models.ModelType' failed because no type converter can convert between these types."
This only seems to affect actions coming from the Kendo UI grid, normal MVC action posts work regardless of the name of the action parameter.
I was able to create a new project with a small test model and recreate this behavior as well.
Can anyone shine some light on what is going on here?
回答1:
Most probably the current "ModelType" contains property with name "Model" and the Default MVC ModelBinder tries to bind the "Model" property to the model variable. You should change the variable name from the action parameters to one that is not contained in the current model.
来源:https://stackoverflow.com/questions/15549495/model-binding-to-action-is-always-null-if-the-parameter-is-named-model-for-ken