I'm using asp.mvc. In my route has the ID, the address of the page for example has link .
I wanted to get this number 1 at the bottom of the page, is there any way to do that?
I'm using asp.mvc. In my route has the ID, the address of the page for example has link .
I wanted to get this number 1 at the bottom of the page, is there any way to do that?
The default route looks something like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
Note that a id is passed at the end of it, so when you have a route, example: link means that you can get this value by creating a id variable in action
public ActionResult SuaAction(int? id) {}
Now if you want to pass as link , you would need to create a custom route that would look like this:
routes.MapRoute(
name: "RotaCustom",
url: "SuaURL/{id}",
defaults: new { controller = "Controller", action = "Action" },
constraints: new { id = @"\d+" }
);
You can retrieve the last segment, for example:
// http://usuario/1
string url = Request.Url.AbsoluteUri;
string id = url.Substring(url.LastIndexOf('/') + 1);
//resultado: 1