0

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?

2 Answers 2

1

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)
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

ParentActionViewContext is null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.