考虑以下标记: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