I have something like this:
public ActionResult ImageReplace(int imgid,HttpPostedFileBase file)
{
string keyword = imgid.ToString();
.......
}
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" />
}
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
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" />
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With