Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在视图中的字符串中使用razor_C#_Asp.net_Razor - Fatal编程技术网

C# 在视图中的字符串中使用razor

C# 在视图中的字符串中使用razor,c#,asp.net,razor,C#,Asp.net,Razor,我试图把一些剃须刀的东西放在一个链接里,但不能让它正确注册。出错的部分是@{@Url 以下是我正在使用的方法帮助器: public static class UrlHelperExtension { public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, object routeValues = null) { string

我试图把一些剃须刀的东西放在一个链接里,但不能让它正确注册。出错的部分是@{@Url

以下是我正在使用的方法帮助器:

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);
    }
您尝试在Razor块中使用Razor代码。若要修复此问题,只需删除@{…}:

您尝试在Razor块中使用Razor代码。若要修复此问题,只需删除@{…}:


基本上,您必须删除@{},但是

创建辅助对象:

@helper MailToThing(string email, string body, string title, string subject) {
    <a class="social-icons-anchor" href="mailto:@email?subject=@subject&body=@body">@title</a>
}
然后渲染:

@MailToThing(email, body, "", "Check out this blah! - Blah")

基本上,您必须删除@{},但是

创建辅助对象:

@helper MailToThing(string email, string body, string title, string subject) {
    <a class="social-icons-anchor" href="mailto:@email?subject=@subject&body=@body">@title</a>
}
然后渲染:

@MailToThing(email, body, "", "Check out this blah! - Blah")

您不需要@2次。只需使用@Url.AbsoluteAction,您就会很好。它完全按照您的要求执行:您的AbsoluteAction调用参数中有一个空格,因此您的输出中有一个空格URL@Jimmyt1988注意你在Url.AbsoluteAction Details的空白处。谢谢Mannnn!你不需要@2次。只要使用@绝对动作,你会做得很好。它完全按照你的要求做:绝对动作调用参数中有一个空格,所以输出中有一个空格URL@Jimmyt1988注意你在Url.AbsoluteAction Details的空白处。谢谢!
@{
 var body = @Url.AbsoluteAction("Details", "Blah" , new { blahID = Model.Blah.BlahID });
 var email = "brahbrahbrah@bbhmm.com";
}
@MailToThing(email, body, "", "Check out this blah! - Blah")