Get value from url on post method mvc3
I needed to get a data from the url on my post method. I have this routing
on my asax:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Then on my Home Controller, under Get:
[HttpGet]
public ActionResult Index()
{
var id = ControllerContext.RouteData.GetRequiredString("id");
}
And on Post:
[HttpPost]
public ActionResult SomeNewNameHere(HomeModel homeModel)
{
var id = ControllerContext.RouteData.GetRequiredString("id");
}
My problem here is I need that id from the url on my post method. By
debugging, I noticed that it gets the id on the get method, but when i
post it, it returns me a null resulting to an error. Anything I missed
here? Thanks!
Sample url:
http://localhost:1000/Controller/Action/12312121212
No comments:
Post a Comment