我想在ASP.NET MVC 4應用程序中設置登錄表單。目前,我已經配置了我的看法如下所示:在ASP.NET MVC中路由GET和POST路由4
RouteConfig.cs
routes.MapRoute(
"DesktopLogin",
"{controller}/account/login",
new { controller = "My", action = "Login" }
);
MyController.cs
public ActionResult Login()
{
return View("~/Views/Account/Login.cshtml");
}
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model)
{
return View("~/Views/Account/Login.cshtml");
}
當我試圖訪問在/帳號/登錄瀏覽器,我收到一個錯誤,說:
The current request for action 'Login' on controller type 'MyController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Login() on type MyApp.Web.Controllers.MyController
System.Web.Mvc.ActionResult Login(MyApp.Web.Models.LoginModel) on type MyApp.Web.Controllers.MyController
如何在ASP.NET MVC 4中設置基本表單?我已經看了ASP.NET MVC 4中的示例Internet應用程序模板。但是,我似乎無法弄清楚路由是如何連接的。非常感謝你的幫助。
你想用自定義路線實現什麼?乳清沒有保留默認路線({controller}/{action}/{id})?默認路線應該可以正常工作。 –
@KevinJunghans - 如果您沒有注意到,他的控制器名稱與他的網址不同 –
什麼是[[ViewSettings(Minify = true)]?我無法找到對此屬性的任何參考。這是你創造的東西嗎? –