[英]Creating Url.Action causes URL string to build incorrectly
我有一個按鈕,其onclick函數為onclick="location.href='@Url.Action("SendRegisterLink?Email="+ item.Email, "Account")'"
按鈕工作,URL構建,我有一些JS從URL中抓取“電子郵件”字段 - 但我沒有得到正確的輸出:
預期網址
/Account/SendRegisterLink?Email=test@test.com
實際網址
/Account/SendRegisterLink%3fEmail%3dtest%40test.com
你需要使用
@Url.Action("SendRegisterLink, "Account", new { Email= item.Email});
看看函數的實際參數。 你可以在最新的vs中使用ctrl + click來檢查它的參數。
public static string Action(this IUrlHelper helper, string action, string controller, object values);
如果要使用Action
函數,可以使用該重載。 第一個參數只需要您的操作名稱作為字符串名稱。 所以你可以像這樣使用它:
@Url.Action("SendRegisterLink", "Account", new { item.Email })
如果要直接提及帶參數的URL,可以使用Content
函數:
@Url.Content("~/Account/SendRegisterLink?Email=" + item.Email)
如果您的意圖只是一個重定向,您還可以使用標記清理:
<a href="~/Account/SendRegisterLink?Email=@item.Email">My Link</a>
您始終可以更改錨標記的CSS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.