我遇到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]'方法 –