I’ve got a view that is strongly typed to an object, for example let’s say a car object. The car object has a name and description. I’d like to be able to have a dynamic number images uploaded, maybe using the Jquery upload plugin, with the the car object, as well as some meta data for the image like date taken. So how would one use a strongly typed view and a dynamic number of image uploads?
I’ve found a few examples online for this but they use the creation of a new form and therefore the images would go to a different action. Is there a way to have the car model plus the uploaded images data go to the same action?
Is this possible?
[HttpPost]
public ActionResult Add(Car car, IEnumerable<HttpPostedFileBase> files)
{
return View();
}
@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Car information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.Name)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Name)
@Html.ValidationMessageFor(m => m.Name)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Description)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Description)
@Html.ValidationMessageFor(m => m.Description)
</div>
<label for="file1">Filename:</label>
<input type="file" name="files" id="file1" />
<label for="file2">Filename:</label>
<input type="file" name="files" id="file2" />
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
</div>
}
As you are going for dynamic upload following thing help you in ASP.net MVC 3.
Now do following thing
Hope this step help you to create your solution.