Reputation: 18630
Hi have an MVC page that shows up with the url like:
When I'm at this page I run some jquery that calls another method in the controller. In this new method I want to get the 2 from http://myhost/Invoice/Edit/2. One problem is now that I've called the new method the Request.Url
has obviously changed from http://myhost/Invoice/Edit/2 to be different.
Can anyone tell me in this situation how I would get the 2?
Upvotes: 0
Views: 531
Reputation: 1038780
I run some jquery that calls another method in the controller.
You haven't shown how exactly this script is calling your other controller action but you should pass the initial id as parameter to this action. For example if you were doing an AJAX call or something:
$.post('@Url.Action("Edit")', new { invoiceId = '@Model.Id' }, function() {
...
});
and in the controller action:
[HttpPost]
public ActionResult Edit(int invoiceId)
{
...
}
Upvotes: 1
Reputation: 1036
ControllerContext.ParentActionViewContext.RouteData.Values["id"]
Upvotes: 0