C# ASP.NET核心MVC Web应用程序在Id之前不附加斜杠
我正在观看一些学习ASP.NET Core的教程。我正在创建一个MVC Web应用程序。在网站中,我有产品的编辑选项。当我单击“编辑”按钮时,它会转到此url “” 它给了我一个错误,它应该转到 “” 但事实并非如此。我该如何解决这个问题 Product/Index.cshtmlC# ASP.NET核心MVC Web应用程序在Id之前不附加斜杠,c#,url,controller,asp.net-core-mvc,trailing-slash,C#,Url,Controller,Asp.net Core Mvc,Trailing Slash,我正在观看一些学习ASP.NET Core的教程。我正在创建一个MVC Web应用程序。在网站中,我有产品的编辑选项。当我单击“编辑”按钮时,它会转到此url “” 它给了我一个错误,它应该转到 “” 但事实并非如此。我该如何解决这个问题 Product/Index.cshtml @model IEnumerable<NewGraniteHouse.Models.Products> @{ ViewData["Title"] = "Index"; } <br /><
@model IEnumerable<NewGraniteHouse.Models.Products>
@{
ViewData["Title"] = "Index";
}
<br /><br />
<div class="row">
<div class="col-6">
<h2 class="text-info">Product List</h2>
</div>
<div class="col-6 text-right">
<a asp-action="Create" class="btn btn-info"><i class="fas fa-plus"></i> New Product</a>
</div>
</div>
<br />
<div>
<table class="table table-striped border">
<tr class="table-info">
<th>
@Html.DisplayNameFor(m => m.Name)
</th>
<th>
@Html.DisplayNameFor(m => m.Price)
</th>
<th>
@Html.DisplayNameFor(m => m.Available)
</th>
<th>
@Html.DisplayNameFor(m => m.ProductTypes)
</th>
<th>
@Html.DisplayNameFor(m => m.SpecialTags)
</th>
<th></th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(m => item.Name)
</td>
<td>
@Html.DisplayFor(m => item.Price)
</td>
<td>
@Html.DisplayFor(m => item.Available)
</td>
<td>
@Html.DisplayFor(m => item.ProductTypes.Name)
</td>
<td>
@Html.DisplayFor(m => item.SpecialTags.Name)
</td>
<td>
<partial name="_TableButtonPartial" model="item.Id" />
</td>
</tr>
}
</table>
</div>
@model IEnumerable
@{
ViewData[“标题”]=“索引”;
}
产品清单
编辑:添加了cshtml文件。从局部视图来看,似乎您必须将
Id
作为参数传递给控制器方法,但您将其编写为
@Url.Action("Edit"+Model)
但满足您需求的最佳方法重载是@Url.Action(字符串actionName,对象routeValue)
现在你的动作链接将被修改,看起来像
@Url.Action("Edit", new {id = Model})
现在你的局部视图看起来像
@model int
@*
有关为空项目启用MVC的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=397860
*@
从您的局部视图来看,似乎您必须将Id
作为参数传递给控制器方法,但您将其编写为
@Url.Action("Edit"+Model)
但满足您需求的最佳方法重载是@Url.Action(字符串actionName,对象routeValue)
现在你的动作链接将被修改,看起来像
@Url.Action("Edit", new {id = Model})
现在你的局部视图看起来像
@model int
@*
有关为空项目启用MVC的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=397860
*@
添加。我尝试将“href=”@Url.Action(“编辑”+Model)”更改为“href=”@Url.Action(“编辑/”+Model)”,但它会转到“仍然不起作用”。添加。我尝试将“href=”@Url.Action(“编辑”+Model)”更改为“href=”@Url.Action(“编辑/“+Model)”,但它会转到“仍然不起作用”。