I have the following MVC form and controller to upload an image for merchandise with a given id. The id is null when this form is submitted to the controller for some reason. I checked in the rendered HTML and the correct ID is being rendered on the webpage.
The form:
@using(Html.BeginForm(new{id = ViewBag.id})){
<input type="hidden" name="id" id="id" value="@ViewBag.Id"/>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="submit" />
}
And the controller:
[HttpPost]
public ActionResult AddImage(int merchandiseId, HttpPostedFileBase image)
<snip>
Why would submitting this form cause merchandiseId to be null?
Becouse you use wrong names. Change
to
or
to