我正在尝试将一些Razor内容放入链接中,但无法正确注册。出错的部分是@{ @Url...
<a class="social-icons-anchor" HREF="mailto:?subject=Check out this blah! - Blah&body=@{ @Url.AbsoluteAction(" Details", "Blah" , new { blahID = Model.Blah.BlahID }); }">
将此类链接放入的正确方法是什么?
修改
结果似乎是这样(注意间距):
https://blah-blahdev.azurewebsites.net/blah/ details?blahID=121
以下是我正在使用的方法助手:
public static class UrlHelperExtension
{
public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, object routeValues = null)
{
string scheme = url.RequestContext.HttpContext.Request.Url.Scheme;
return url.Action(actionName, controllerName, routeValues, scheme);
}
答案 0 :(得分:4)
您尝试在Razor
块中使用Razor
代码。要解决此问题,请删除@{
... }
:
<a class="social-icons-anchor" HREF="mailto:?subject=Check out this blah! - Blah&body= @Url.AbsoluteAction(" Details", "Blah" , new { blahID = Model.Blah.BlahID })">
答案 1 :(得分:2)
基本上你必须删除@ {},但是。
创建帮助器:
@helper MailToThing(string email, string body, string title, string subject) {
<a class="social-icons-anchor" href="mailto:@email?subject=@subject&body=@body">@title</a>
}
然后你必须得到等等,等等:
@{
var body = @Url.AbsoluteAction("Details", "Blah" , new { blahID = Model.Blah.BlahID });
var email = "brahbrahbrah@bbhmm.com";
}
然后渲染:
@MailToThing(email, body, "", "Check out this blah! - Blah")