I have an ASP.NET MVC4 application that is using jQuery to make some calls to a WebApi controller in the same project. Passing an ID to the controller, /MyController/123 should display different data when the page is loaded. The problem is that I don’t know how to get that ID passed to jQuery. It’s not a query string parameter per se, so this won’t work. What I want is the “123” from the URL. Is there a common/standard way to do this short of just chopping up the URL?
I have an ASP.NET MVC4 application that is using jQuery to make some calls
Share
you can either put it in a ViewBag object in the controller, ViewBag.PassedId = Id, and then on the front end use the razor or whatever view engine method to place it into a javascript variable,
Or you can attach it to a hidden form element and grab the value there. But you would tie an object model to pass from the controller.