2017-06-13 44 views
0

我有以下的剃刀代码:为什么表单的动作属性使用相同的代码有什么不同?

@using (Html.BeginForm("Login", "Account", FormMethod.Post,... 

直到今天,这已经产生了这样的HTML(我想):

<form action="/Account/Login" method="post" ... 

但最近开始输出这个HTML:

<form action="/form?action=Login&amp;controller=Account" ... 

什么可以这样做的原因?我并没有改变任何视图或控制器的代码,但它suddely开始输出不同的HTML。

+1

你改变routeconfig?什么是提交类型?看起来它正在做一个GET而不是POST。 – itsme86

回答

2

MVC匹配路线的顺序,他们是注册用户,第一场比赛总是获胜。最有可能你已经添加另一条路线该路由你正打算这个打匹配controller=Accountaction=Login(通过会议或基于属性的路由)。

// Your form will always match this route because it uses the 
// same controller and action values, as a result it can never 
// match your Default route. 
routes.MapRoute(
    name: "UnintendedMatch", 
    url: "form", 
    defaults: new { controller = "Account", action = "Login" } 
); 

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
); 
+0

这是极其严重的事情。 – MaxP

相关问题