c# - Url.Action 方法返回错误的 url 字符串
问题描述
我正在尝试使用以下代码生成 url 字符串:
var x = @Url.Action("AddOrEditSaleOffer", "BuildingOffers", null);
但是,返回的值会以某种方式生成以下 url:
/BuildingOffers/AddOrEditSaleOffer/7
其中 7 是根据上次编辑的商品的 ID 更改的数字。
该代码位于部分视图中,并在对 Building Offer 记录进行编辑后使用 ajax 调用进行调用。我希望得到 NO id,但 url 以某种方式附加了一个 id。
更新:
我发现以下问题有助于理解我遇到此问题的原因并建议解决方法:防止 URL 中的环境路由值自动添加到 ASP.NET 中的 Html.Action 和 Html.ActionLinks
此外,Microsoft Docs 中的以下部分。讨论这个问题:https ://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0#url-generation-reference
解决方案
If you don't want to send parameters in your url, you can use the other Action method overload, which takes controller and action as input parameters.
var url = @Url.Action("AddOrEditSaleOffer", "BuildingOffers");
推荐阅读
- c# - 如何在 C# 中通过其程序集名称/默认命名空间获取程序集
- c# - 如何将 2 个不同的数据源添加到不同列中的单个 gridview?
- node.js - 'submodule' 似乎是一个 git 命令,但我们无法执行它
- vb.net - Async Sub() 或 Async Function() 作为 Fire and Forget 的任务?
- php - 删除重复项并按行计数
- c - 获取 sizeof 可变数量的参数
- php - Symfony 守卫抛出 AuthenticationException 但用户加载成功
- mysql - MySQL时间与十进制
- xamarin - xamarin.forms java.exe 在 vs 2017 中以代码 2 退出
- c# - 循环遍历每个类属性并使用反射获取它的值