![](/img/trans.png)
[英]Custom routes for controller with Html.ActionLink and Url.Action
[英]Converting @Html.ActionLink to @Url.Action
我正在嘗試將其轉換為:
@Html.ActionLink("Register", "Register", "Account",
routeValues: null, htmlAttributes: new { id = "registerLink" })
對此
<input type="button" title="Register"
onclick="location.href='@Url.Action("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" }
我一直在htmlAttributes上犯錯。 我試圖使第一個鏈接成為按鈕,但保持相同的屬性。 有什么建議嗎?
HTML屬性必須添加到html :)中,例如:
<input type="button" title="Register" id="registerLink"
onclick="location.href='@Url.Action("Register", "Account")'" />
<input type="button" title="Register" id="registerLink"
onclick="window.location='@Url.Action("Register", "Account")'" />
它將起作用,我已經嘗試了其他ans。 但這可以是一種選擇。
@Url.Action
既沒有linkText
也沒有htmlAttributes
參數。 您可以做的是直接使用HTML id
和value
屬性。
在下面的示例中,我就這樣做了,並使用了命名參數來說明@Url.Action
和@Html.ActionLink
之間的區別。
@Html.ActionLink(
linkText: "Register",
actionName: "Register",
controllerName: "Account",
routeValues: null,
htmlAttributes: new { id = "registerLink" })
<input
id="registerLink"
type="button"
title="Register"
value="Register"
onclick="location.href='@Url.Action(
actionName: "Register",
controllerName: "Account",
routeValues: null)'" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.