2017-06-13 16 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

相關問題