MVC: Upload image in partial view, routing problem

Posted by D.J on Stack Overflow See other posts from Stack Overflow or by D.J
Published on 2010-05-19T04:08:42Z Indexed on 2010/05/19 4:10 UTC
Read the original article Hit count: 259

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

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about partial-views