Asp.net mvc 3 参数字典包含一个空条目;
我有一个我似乎无法解决的问题。我正在向我的控制器发布数据。控制器声明如下所示:Asp.net mvc 3 参数字典包含一个空条目;,asp.net-mvc-3,Asp.net Mvc 3,我有一个我似乎无法解决的问题。我正在向我的控制器发布数据。控制器声明如下所示: public ActionResult Create(string Title, string Description, string Payment, string Adress, string ZIP, float Longitude, float Latitude) 使用Fiddler,发布的数据如下所示 我在发布时收到此错误消息: 参数字典包含“GjorWebRole.Controllers.MyCont
public ActionResult Create(string Title, string Description, string Payment, string Adress, string ZIP, float Longitude, float Latitude)
使用Fiddler,发布的数据如下所示
我在发布时收到此错误消息:
参数字典包含“GjorWebRole.Controllers.MyController”中不可为null类型“System.Single”for method“System.Web.Mvc.ActionResult Create(System.String,System.String,System.String,System.String,System.String,Single,Single)”的参数“经度”的null
条目。可选参数必须是引用类型、可为null的类型或声明为可选参数。
参数名称:参数
如参数表所示,按经度(浮点)参数的顺序发送城市值(字符串)。尝试在经度参数之前将城市参数添加到动作方法中
public ActionResult Create(string Title, string Description, string Payment, string Adress, string ZIP,string City, float Longitude, float Latitude)
更新
根据您的评论,Create
方法声明应该如下
[HttpPost]
public ActionResult Create(FormCollection myform)
{
String Title = myform["Title"];//title is the name of html tag
Strign ZIP = myform["ZIP"];//ZIP is the name of html tag
.
.
.
}
如中所述,MVC没有为开箱即用的浮动提供
ModelBinder
。如果希望操作接受浮点参数,则必须创建自己的操作。能否向我们展示如何调用此操作方法?这可能是一个编码问题。您的浏览器/服务器文化是什么?经度值15.628
是否是您所在文化的有效数字?尝试发送15628
订单真的重要吗?我将City参数添加到action-method-arguments列表中,其顺序与post-now相同,但结果相同:/如何调用此action-method?它是通过表单posting-data调用的,其中“My”是控制器,“Create”是操作
是否使用HttpPost
属性装饰创建
方法?如果没有,请尝试执行。MVC使用参数的名称以及模型绑定系统可以从注册的ValueProvider
s获得的任何数据将参数值绑定到操作参数。已发布数据中参数的顺序是不相关的。