Pass multiple parameters in Html.BeginForm MVC4 controller action
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" />
}
You can also pass imgid
as a field in the form, something like:
@model Models.MemberData
@using (Html.BeginForm("ImageReplace", "Member", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
@Html.HiddenFor(x => x.Id)
<input type="file" name="file" id="file" value="Choose Photo" />
<input type="submit" name="submit" value="Submit" />
}
Use this:
@using (Html.BeginForm("ImageReplace", "Member",
new { imgid = @Model.Id }, FormMethod.Post,
new { enctype = "multipart/form-data" }))