Creating a URL in the controller .NET MVC

后端 未结 5 2055
無奈伤痛
無奈伤痛 2020-11-30 18:43

I need to be able to construct a link in the Action on the controller to send an email. What is best practice to do this? I don\'t want to construct it myself in case my ro

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 19:26

    I know this is an old question, but just in case you are trying to do the same thing in ASP.NET Core, here is how you can create the UrlHelper inside an action:

    var urlHelper = new UrlHelper(this.ControllerContext);
    

    Or, you could just use the Controller.Url property if you inherit from Controller.

提交回复
热议问题