MVC 4页改变Html.beginform后不工作() [英] MVC 4 Page not working after altering Html.beginform()

查看:222
本文介绍了MVC 4页改变Html.beginform后不工作()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这条线我edit.cshtml页面的顶部被:

I had been using this line at the top of my edit.cshtml page:

@using(Html.BeginForm())

但后来我把它改为:

@using(Html.BeginForm(编辑,家,FormMethod.Post,新{ENCTYPE =的multipart / form-data的}))

,现在当我点击提交该网页上我尝试运行此方法:

and now when I hit submit on that page I try to run this method:

公众的ActionResult编辑([绑定(包括=描述,标签,档案,fileString)工作任务,诠释的keyid,串editFiles)

我得到这个错误:

参数词典共包含参数提供一个空的条目的keyid
  非可空类型'System.Int32'的方法
  System.Web.Mvc.ActionResult编辑(Combined.Models.Task,的Int32,
  在'Combined.Controllers.HomeController System.String)。可选
  参数必须是引用类型,可空类型,或声明为
  一个可选参数。参数名:参数说明:
  当前Web的执行过程中发生未处理的异常
  请求。请检查堆栈跟踪有关的详细信息
  错误以及它起源于code。

The parameters dictionary contains a null entry for parameter 'keyId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Combined.Models.Task, Int32, System.String)' in 'Combined.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.ArgumentException:参数
  词典共包含参数空项非空的的keyid
  类型'System.Int32'的方法'System.Web.Mvc.ActionResult
  编辑(Combined.Models.Task,的Int32,System.String)中
  Combined.Controllers.HomeController。一个可选的参数必须是
  引用类型,可空类型,或声明为可选
  参数。参数名:参数

Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'keyId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Combined.Models.Task, Int32, System.String)' in 'Combined.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

源错误:

的执行过程中生成了未处理的异常
  当前Web请求。有关的起源和位置信息
  除了可以使用异常堆栈跟踪下面来识别。

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

我试图改变行:

@using(Html.BeginForm(编辑,家,FormMethod.Post,新{ENCTYPE =多部分/表单数据的keyid = Model.keyId}))

但它并没有任何区别。我在做什么错了?

but it didn't make any difference. What am I doing wrong?

推荐答案

添加到KEYID窗体作为隐藏输入,而不是在路由参数,因为你发布。

Add KeyId to the form as a hidden input instead of in the route parameters, since you are posting.

@Html.HiddenFor(model => model.keyId)

(实际上,你是将其添加为HTML属性。查看源代码的网页,并期待在那里被渲染。)

(Actually, you are adding it as an Html Attribute. View source on your page and look where it is being rendered.)

这篇关于MVC 4页改变Html.beginform后不工作()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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