How to generate a path/url from a Route in the Routes table?

前端 未结 1 590
猫巷女王i
猫巷女王i 2021-01-27 13:23

I have an ASP.NET MVC web application, and I\'ve registered a number of routes in my Global.asax.

I would like to know how I can programmatically build (generate a strin

相关标签:
1条回答
  • 2021-01-27 13:26

    You could use the UrlHelper class inside your controller action.

    public ActionResult Index()
    {
        string address = Url.RouteUrl(new { 
            action = "foo", controller = "bar", id = "123" 
        });
        // TODO: do something with the url
    
        return View();
    }
    
    0 讨论(0)
提交回复
热议问题