Just to clarify, it works when using a regular GET type URL (eg, /Panel?EntityId=9140), but not once it is routed it (eg, /Panel/SignalHistory/9141) throws the error.
Just to clarify, it works when using a regular GET type URL (eg, /Panel?EntityId=9140), but not once it is routed it (eg, /Panel/SignalHistory/9141) throws the error.
by default the route table puts route parameters into a variable called Id. If you want to change that you can make changes in the RouteConfig.cs file.
To get it working as it, simply pass a variable called Id to your action method.
public ActionResult SignalHistory(int id){
// id now should be 9141 or whatever is in the URL
}
Mason240
Member
17 Points
13 Posts
Get a routing value from the URL.
Dec 20, 2012 03:25 PM|LINK
I would like get the last value from the this URL:
This is the URL before routing:
How would I go about this? Thanks.
calibur
Member
300 Points
124 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 03:29 PM|LINK
Request.QueryString[0]
quantt
Member
215 Points
38 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 03:36 PM|LINK
In your action , you can use EntityId as parameter:
public ActionResult(int EntityId) { return View(); }Or you can get it from Request.QueryString
public ActionResult() { var entityId=Request.QueryString["EntityId"]; return View(); }Quan Truong
Please, click 'Mark as answer' if you think my answer really help you. Thanks
Mason240
Member
17 Points
13 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 03:54 PM|LINK
This actually doesn't work. I get an error that index for Request.Query string is out of range.
Mason240
Member
17 Points
13 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 05:15 PM|LINK
Just to clarify, it works when using a regular GET type URL (eg, /Panel?EntityId=9140), but not once it is routed it (eg, /Panel/SignalHistory/9141) throws the error.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 05:46 PM|LINK
by default the route table puts route parameters into a variable called Id. If you want to change that you can make changes in the RouteConfig.cs file.
To get it working as it, simply pass a variable called Id to your action method.
public ActionResult SignalHistory(int id){ // id now should be 9141 or whatever is in the URL }Blog | Twitter : @Hattan
quantt
Member
215 Points
38 Posts
Re: Get a routing value from the URL.
Dec 20, 2012 06:39 PM|LINK
You can use parameter id in your action as below :
public ActionResult SignalHistory(int id) { return View(); }Quan Truong
Please, click 'Mark as answer' if you think my answer really help you. Thanks
calibur
Member
300 Points
124 Posts
Re: Get a routing value from the URL.
Dec 21, 2012 03:00 PM|LINK
You could also try this:
The syntax differs slightly between MVC 3 and MVC 4.