MVC: Upload image in partial view, routing problem
- by D.J
I am trying to upload images via a form which sits in partial view using MVC.
View Code:
<form action="/Item/ImageUpload" method="post" enctype="multipart/form-data">
<%= Html.TextBox("ItemId",Model.ItemId) %>
<input type="file" name="file" id="file" />
<input type="submit" value="Add" />
</form>
Action Code:
public void ImageUpload(string ItemId, HttpPostedFileBase file)
{
// upload image
// Add Image record to database
// Associate Image record to Item record
//Go back to existing view where the partial view sits
RedirectToAction("Details/"+ItemId);
}
The Image is uploaded successful
All the data manipulation are working as expected
However instead of redirect to view "Item/Details/id", page went to "/Item/ImageUpload"
I tried several different way of doing this including using jsonResultAction, but all failed in this same result.
where did i do wrong, any ideas? thanks in advance