嘗試使用ActionLink
助手的正常過載(是的,有過載的gazillions):
@Html.ActionLink(
"Sign Out", // linkText
"LogOff", // actionName
"Account", // controllerName
null, // routeValues
new { @class = "btn blue" } // htmlAttributes
)
,而你使用:
@Html.ActionLink(
"Sign Out", // linkText
"LogOff", // actionName
"Account", // routeValues
new { @class = "btn blue" } // htmlAttributes
)
瞭解爲什麼你的代碼不管用?
是的,微軟對這些超負荷做了一個混亂,如果你不小心,你陷入陷阱。
解決方案:讀取MSDN
或使用Visual Studio智能感知(F12,而您的光標在ActionLink助手上)。
出於這個原因,我更願意把它寫在使用C#4.0的命名參數的模式明確的方式:
@Html.ActionLink(
linkText: "Sign Out",
actionName: "LogOff",
controllerName: "Account",
routeValues: null,
htmlAttributes: new { @class = "btn blue" }
)
啊,達林拍我來吧 – pinmonkeyiii