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
Edit:
I just realized all the routing which are render by the code is not working.
for example: [ <%= Html.ActionLink("Log Off", "LogOff", "Account") %> ]
instead of rendering <a href="/Account/LogOff">Home</a>
it renders <a href="">Home</a>
however all the routings which were hard coded are all working.
Where did i break it?? It troubles that I cant event restore it.
Code for Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapRoute(
// "ImageResize",
// "{controller}/{action}/{id}/{value}",
// new { controller = "Image", action = "ShowImage", id = "", value = "" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}