我遇到ASP.NET BeginForm
帮助程序的问题。ASP.NET HTML.BeginForm/Url.Action Url指向自己
我试图创建应指向/Project/Delete
一种形式,我尝试了以下众所周知声明来实现这一目标:
@using (Html.BeginForm("Delete", "Project"))
{
}
<form action="@Url.Action("Delete", "Project")"></form>
但不幸的是渲染操作点既/Projects/Delete/LocalSqlServer
,这是网站的所谓的网址浏览器
<form action="/Project/Delete/LocalSqlServer" method="post"></form>
我真的不知道为什么渲染的动作指向自身,而不是给出route.I已经阅读谷歌的所有帖子(我发现)和SO,但没有发现任何解决方案。
这是定义的唯一途径:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这是我的控制器
[HttpGet]
public ActionResult Delete(string id)
{
return View(new DeleteViewModel { Name = id });
}
[HttpPost]
public ActionResult Delete(DeleteViewModel model)
{
_configService.DeleteConnectionString(model);
return null;
}
我使用.NET 4.6.2。
我真的很感谢你的帮助。
感谢 桑德罗
我碰到类似的东西,会看看我是否能找到你的github问题。 – nurdyguy
你能告诉我们删除操作方法吗? – Win
您需要显示您的路由定义以及'[HttGet]'和'[httpPost]'方法 –