模型结合的行动总是空,如果参数名为"模型"对于剑道UI网格创建操作 [英] Model binding to action is always null if the parameter is named "model" for kendo ui grid create actions

查看:100
本文介绍了模型结合的行动总是空,如果参数名为"模型"对于剑道UI网格创建操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里正在从剑道UI网格的创建活动产生的请求的操作。这些信息都被正确张贴,并模型绑定工作在那里的行动参数名称为模型

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'

如果操作的定义如下:

[HttpPost]
public ActionResult Create(ModelType post)
{                                                                                                    
}

一切工作正常。

如果不是虽然动作看起来是这样的:

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

System.Web.Mvc.ModelError

从类型'System.String'的参数转换为类型
  MyApp.Common.Models.ModelType'失败,因为没有类型转换器可以转换之间
  这些类型的。

The parameter conversion from type 'System.String' to type 'MyApp.Common.Models.ModelType' failed because no type converter can convert between these types."

这似乎只影响从剑道UI电网未来的行动,正常的MVC动作岗位工作无关的操作参数的名称。

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?

推荐答案

最有可能目前的ModelType包含name属性模型和MVC模型绑定器试图模型属性绑定到模型变量的默认。您应该未包含在当前模型中的动作参数一个改变变量名。

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.

这篇关于模型结合的行动总是空,如果参数名为"模型"对于剑道UI网格创建操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆