创建控制器.NET MVC的URL [英] Creating a URL in the controller .NET MVC
本文介绍了创建控制器.NET MVC的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够构建控制器上操作的链接发送电子邮件。什么是做到这一点的最佳做法?我不想构建它自己的情况下,我的路线发生改变。
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 routes change.
我应该为每个邮件视图和渲染,并将其发送?这可能是做这件事的好方法。
Should I have a view for each email and render that and send it? That might be a good way of doing it.
推荐答案
如果你只是想获得一定的行动路径,使用 UrlHelper
:
If you just want to get the path to a certain action, use UrlHelper
:
UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
string url = u.Action("About", "Home", null);
如果你想创建一个超链接:
if you want to create a hyperlink:
string link = HtmlHelper.GenerateLink(this.ControllerContext.RequestContext, System.Web.Routing.RouteTable.Routes, "My link", "Root", "About", "Home", null, null);
智能感知会给你每个参数的意义。
Intellisense will give you the meaning of each of the parameters.
这篇关于创建控制器.NET MVC的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文