2015-07-28 78 views
1

我想在一個鏈接中放置一些剃鬚刀的東西,但不能完全讓它註冊正確。這是怎麼回事錯的部分是@{ @Url...在視圖中使用剃鬚刀內的字符串

<a class="social-icons-anchor" HREF="mailto:?subject=Check out this blah! - Blah&[email protected]{ @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

你不需要@ 2次。你只需要使用@ Url.AbsoluteAction(),你就會好起來的 – greenhoorn

+0

它正在做你所問的:你的AbsoluteAction調用參數有一個空格,所以你的輸出URL有一個空格 –

+2

@ Jimmyt1988注意你在Url中的空間。 AbsoluteAction(「詳細信息」) – greenhoorn

回答

4

你試試使用Razor塊內的代碼。爲了解決這個問題,只是刪除@{ ... }

<a class="social-icons-anchor" HREF="mailto:?subject=Check out this blah! - Blah&body= @Url.AbsoluteAction(" Details", "Blah" , new { blahID = Model.Blah.BlahID })"> 
2

基本上你必須刪除@ {},但。

創建一個幫手:

@helper MailToThing(string email, string body, string title, string subject) { 
    <a class="social-icons-anchor" href="mailto:@[email protected]&[email protected]">@title</a> 
} 

然後,你將必須得到胡說,胡說的東西:

@{ 
var body = @Url.AbsoluteAction("Details", "Blah" , new { blahID = Model.Blah.BlahID }); 
var email = "[email protected]"; 
} 

然後渲染:

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