我試圖在MVC視圖中指定appsetting鍵值+字符串。在帶有字符串的mvc視圖中使用appsetting鍵
我試過@System.Configuration.ConfigurationManager.AppSettings["myKey"].ToString()+"Custom/CustomerProfile.aspx"
,但沒有奏效。周圍的代碼
<a href="here..." id="doneLink" class="btn btn-primary">Done</a>
我試圖在MVC視圖中指定appsetting鍵值+字符串。在帶有字符串的mvc視圖中使用appsetting鍵
我試過@System.Configuration.ConfigurationManager.AppSettings["myKey"].ToString()+"Custom/CustomerProfile.aspx"
,但沒有奏效。周圍的代碼
<a href="here..." id="doneLink" class="btn btn-primary">Done</a>
認沽括號,使其明確表達:
<a href="@(
System.Configuration.ConfigurationManager.AppSettings["myKey"].ToString()+"Custom/CustomerProfile.aspx"
)" id="doneLink" class="btn btn-primary">Done</a>
下面是菲爾哈克了速查手冊:
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
該作品爲了我。你有什麼具體的錯誤?
<a href="@System.Configuration.ConfigurationManager.AppSettings["key"]" />
這是我會怎麼做,假設你想使用字符串中的鏈接的href屬性:
@{
var href = System.Configuration.ConfigurationManager.AppSettings["myKey"].ToString() + "Custom/CustomerProfile.aspx";
}
<a href="@href" id="doneLink" class="btn btn-primary">Done</a>
但是,它看起來像您不使用剃刀,因爲你的鏈接以.aspx結尾,而不是.cshtml。是對的嗎?
你的問題不是很清楚。你想在標籤的href屬性中使用該連接字符串嗎? – ataravati
順便說一句,你鏈接在.aspx結束,所以它看起來像你不使用剃刀。是對的嗎? – ataravati