考慮以下標記:ASP.Net MVC模型綁定返回空值
<form method="post" action="/home/index">
Username:
<%= Html.TextBox("UserName")%>
Password:
<%= Html.TextBox("Password")%>
<input id="login" type="button" value="Login" />
<input id="Submit1" type="submit" value="submit" />
</form>
你能告訴我爲什麼模型綁定調用我的操作時不工作:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string UserName, string Password)
{
//UserName and Password are null! Why?
}
編輯: 表單值已發佈。如果我檢查Request.Form屬性,我發現正在發佈的值正確。
?的Request.Form {用戶名= SDF &密碼= SDF} [System.Web.HttpValueCollection]:{用戶名= SDF &密碼= SDF} 基{System.Collections.Specialized.NameObjectCollectionBase}:{用戶名= SDF &密碼= SDF} AllKeys:{字符串[2]}
我假設你檢查了正確的動作張貼表格後打? – 2009-04-23 03:51:04