我使用的是MVC框架中的Ajax.Actionlink
,並且對於我的目標和部分視圖,一切正常。但是我已經看到,html輸出不會將「id」屬性添加到結果<a href=""></a>
標記中。帶有id屬性的Ajax.Actionlink輸出
有沒有什麼辦法可以添加它?
我使用的是MVC框架中的Ajax.Actionlink
,並且對於我的目標和部分視圖,一切正常。但是我已經看到,html輸出不會將「id」屬性添加到結果<a href=""></a>
標記中。帶有id屬性的Ajax.Actionlink輸出
有沒有什麼辦法可以添加它?
您需要在對象htmlAttributes參數中使用new { id = "myId" }
,該參數在其幾個構造函數中可用。或者,您可以使用IDictionary<string, string>
htmlAttributes在其幾個構造函數中填充它。
我相信你正在尋找routeValues參數。
<%= Ajax.ActionLink("SomeAction", "SomeController", new { id = ID_HERE }, null) %>
-1:這是不正確的。這會向路由添加一個參數,而不是錨點標記(OP要求的)的id屬性。 – 2014-01-23 17:15:17
嘗試重載之一,像this one:
public static string ActionLink(
this AjaxHelper ajaxHelper,
string linkText,
string actionName,
Object routeValues,
AjaxOptions ajaxOptions,
Object htmlAttributes
)
然後你就可以在htmlAttributes指定ID參數,例如
new { id = "myIdValue" }
+1:這也是正確的,但5分鐘後...很好的例子。 – 2014-01-23 17:17:18
他需要routeValues參數。 HtmlAttributes會設置錨標籤本身的id屬性。 – 2009-12-09 22:37:24
我對他的問題的理解是,他想要a – 2009-12-09 22:40:09
我認爲這就是要求 - 「將」id「屬性添加到結果標籤」?這個答案聽起來正確。 – 2009-12-09 22:42:27