How do I get parameter value from the URL in the client side, view?
URL:
localhost:18652/category/1
MapRoute:
routes.MapRoute(
name: "ResultsByCategory",
url: "category/{id}",
defaults: new { controller = "Home", action = "ResultsByCategory"}
);
How do I get ID?
Didn't understand the point of directly getting from URL, Request as your view is always going to get loaded from your controller.
So as derloopkat suggested
In your Home Controller
Public ActionResult ResultsByCategory (int id)
{
ViewBag.id = id;
return View();
}
In your view you can use it by calling
@ViewBag.id
此代码更适合您的代码
string id = Request.Path.Value.Split('/').LastOrDefault();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.