在控制器中生成URL时,url不可点击

When generating URL in the controller, the url is not clickable

我在这里看到了一些例子,但实际上我也在做同样的事情,但是,它并不完全有效。所以,这是我的问题:

我的控制器中有生成 URL:

的代码
string link = @Url.Action("Index", "Details", new System.Web.Routing.RouteValueDictionary(new { id = newId }), "http", Request.Url.Host);
var strUrl = "<a href='"
    + @Url.Action("Index", "Details", new System.Web.Routing.RouteValueDictionary(new { id = Id }), "http", Request.Url.Host)
    + "'>Click here</a>";

然后我发邮件:

var response = EmailHelper.SendApproveTicketEmail(myModel.Id, strUrl);

这是我的发送电子邮件代码:

public static SaveResult SendEmail(int ID, string Url)
{
    var email = new Email
    {
        Recipients = Configuration.EmailTo,
        Body = Configuration.EmailBody + ID.ToString() + "." + System.Environment.NewLine + "Click the following link to open the details page:" + ticketUrl,
        Sender = Configuration.EmailFrom,
        Subject = Configuration.EmailSubject,
        Cc = Configuration.EmailCC
    };

    return FormatResult(_client.SendEmail(Configuration.ApplicationName, 0, email));
}

收到以下邮件:

The following item needs to be approved:0011 Click the following link to open the item details page:<a href='http://localhost:51335/Details/Index/001'>Go to your item</a>

URL构建成功,但是无法点击

我错过了什么?

呈现 HTML 锚点时,它至少需要一个 href 和某种对象才能单击。该对象可以是文本或图像。问题是您没有指定文本,因此用户无法点击任何内容。

var ticketUrl = "<a href='"
    + @Url.Action("Index", "TicketDetail", new System.Web.Routing.RouteValueDictionary(new { id = newTicketId }), "http", Request.Url.Host)
    + "'></a>";

您需要在 <a></a> 之间添加一些内容以形成超链接。

var ticketUrl = "<a href='"
    + @Url.Action("Index", "TicketDetail", new System.Web.Routing.RouteValueDictionary(new { id = newTicketId }), "http", Request.Url.Host)
    + "'>Click Me</a>";

要检查的另一件事是您的 MailMessage.IsBodyHtml 是否设置为 true。如果是 false,您的电子邮件将被处理为纯文本而不是 HTML,这意味着它不会处理超链接。