C# 如何在@Html.ActionLink中传递Querystring参数中的字符串
我编写了以下代码:C# 如何在@Html.ActionLink中传递Querystring参数中的字符串,c#,javascript,asp.net,.net,razor,C#,Javascript,Asp.net,.net,Razor,我编写了以下代码: @Html.ActionLink("Edit", "EditPost", new { id = item.PostID }) 它显示的URL类似于../Post/EditPost/32 但实际上我想把它显示为../Post/EditPost?ID=32 在Razor视图中如何可能?URL构造通常由路由决定,如果您想强制它使用查询字符串,则只需从中删除任何参数概念,例如 routes.MapRoute( "EditPostRoute", "Post/EditP
@Html.ActionLink("Edit", "EditPost", new { id = item.PostID })
它显示的URL类似于../Post/EditPost/32
但实际上我想把它显示为../Post/EditPost?ID=32
在Razor视图中如何可能?URL构造通常由路由决定,如果您想强制它使用查询字符串,则只需从中删除任何参数概念,例如
routes.MapRoute(
"EditPostRoute",
"Post/EditPost",
new { controller = "Edit", action = "EditPost" }
);
您的
@Html.ActionLink
代码应生成../Post/EditPost?ID=32
将操作编辑参数从int
更改为string
。然后,它将显示为您想要的
public ActionResult Edit(string ID)
{
=======
=======
}
@Html.ActionLink("Edit", "EditPost", new { ID = item.PostID },null)
另一个解决方案
从Global.asax/Route表中删除id=UrlParameter.Optional