[英]Url.Action method is returning wrong url string
我正在嘗試使用以下代碼生成 url 字符串:
var x = @Url.Action("AddOrEditSaleOffer", "BuildingOffers", null);
但是,返回的值會以某種方式生成以下 url:
/BuildingOffers/AddOrEditSaleOffer/7
其中 7 是根據上次編輯的商品的 ID 更改的數字。
該代碼位於部分視圖中,並使用 ajax 調用並在對 Building Offer 記錄進行編輯后調用。 我希望得到 NO id,但 url 以某種方式附加了一個 id。
更新:
I found the following question helpful to understand why I was facing this problem and also suggested work arounds: Prevent ambient route values from the URL from being added to Html.Action and Html.ActionLinks automatically in ASP.NET
此外,Microsoft Docs 中的以下部分。 討論這個問題: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0#url-generation-reference
如果您不想在 url 中發送參數,則可以使用其他 Action 方法重載,它將 controller 和 action 作為輸入參數。
var url = @Url.Action("AddOrEditSaleOffer", "BuildingOffers");
你可以使用這樣的東西
string url = " /controllerName/ActionName
:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.