在Html.BeginForm MVC4控制器动作中传递多个参数

nee*_*eel 5 c# asp.net-mvc asp.net-mvc-4

我有这样的事情:

   public ActionResult ImageReplace(int imgid,HttpPostedFileBase file)
    {
        string keyword = imgid.ToString();
        .......
    }
Run Code Online (Sandbox Code Playgroud)

在我的.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" />
    }
Run Code Online (Sandbox Code Playgroud)

这里imgid的值没有传递给控制器​​动作.显示错误,参数字典包含参数'imgid'的非可空类型'System.Int32'的空条目,用于方法'System.Web.Mvc.ActionResult ImageReplace

p.s*_*w.g 20

使用此重载,它允许您区分路由值和HTML属性:

@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" />
}
Run Code Online (Sandbox Code Playgroud)