开发者

MVC get URL index value after jquery call

Hi have an MVC page that shows up with the url like:

http://myhost/Invoice/Edit/2

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?


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)
{
    ...
}


ControllerContext.ParentActionViewContext.RouteData.Values["id"] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜