传入Html.BeginForm MVC4控制器操作多个参数 [英] Pass multiple parameters in Html.BeginForm MVC4 controller action
本文介绍了传入Html.BeginForm MVC4控制器操作多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的事情:
public ActionResult ImageReplace(int imgid,HttpPostedFileBase file)
{
string keyword = imgid.ToString();
.......
}
在我的.cshtml:
and in my .cshtml:
@model Models.MemberData
@using (Html.BeginForm("ImageReplace", "Member", FormMethod.Post,
new { imgid = @Model.Id, enctype = "multipart/form-data" }))
{
<input type="file" name="file" id="file" value="Choose Photo" />
<input type="submit" name="submit" value="Submit" />
}
在这里imgid的值不会传递给控制器动作。显示错误,参数词典共包含参数非可空类型'System.Int32'的'imgid'的方法'System.Web.Mvc.ActionResult ImageReplace
here the value of imgid is not passing to controller action. show an error,The parameters dictionary contains a null entry for parameter 'imgid' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ImageReplace
推荐答案
使用的此重载,它允许您路由值和HTML attribtues区分:
Use this overload, which allows you to distinguish between route values and HTML attribtues:
@using (Html.BeginForm(
"ImageReplace", "Member",
new { imgid = @Model.Id },
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" id="file" value="Choose Photo" />
<input type="submit" name="submit" value="Submit" />
}
这篇关于传入Html.BeginForm MVC4控制器操作多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文