我試圖在我的ASP.NET MVC 1項(xiàng)目中使用HTML5數(shù)據(jù)屬性。(我是C#和ASP.NET MVC新手。) <%= Html.ActionLink("? Previous", "Search", new { keyword = Model.Keyword, page = Model.currPage - 1}, new { @class = "prev", data-details = "Some Details" })%>上面的htmlAttributes中的“數(shù)據(jù)細(xì)節(jié)”給出以下錯(cuò)誤: CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.當(dāng)我使用data_details時(shí),它可以工作,但是我想它必須按照規(guī)范以“ data-”開頭。我的問題:是否有任何方法可以使此工作正常運(yùn)行,并將HTML5數(shù)據(jù)屬性與Html.ActionLink或類似的Html幫助器一起使用?還有其他將自定義數(shù)據(jù)附加到元素的替代機(jī)制嗎?稍后將由JS處理此數(shù)據(jù)。
3 回答

慕尼黑的夜晚無繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
它比上面建議的一切還要容易。MVC中包含短劃線(-)的數(shù)據(jù)屬性通過使用下劃線(_)來滿足。
<%= Html.ActionLink("? Previous", "Search",
new { keyword = Model.Keyword, page = Model.currPage - 1},
new { @class = "prev", data_details = "Some Details" })%>
我看到JohnnyO已經(jīng)提到了這一點(diǎn)。
- 3 回答
- 0 關(guān)注
- 651 瀏覽
添加回答
舉報(bào)
0/150
提交
取消