【发布时间】:2009-04-23 01:57:37
【问题描述】:
给定以下标记:
<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 属性,我会看到发布了正确的值。
?申请表 {用户名=sdf&密码=sdf} [System.Web.HttpValueCollection]:{用户名=sdf&密码=sdf} 基础 {System.Collections.Specialized.NameObjectCollectionBase}:{UserName=sdf&Password=sdf} 所有键:{string[2]}
【问题讨论】:
-
我假设您在发布表单后检查了正确的操作?
-
是的,在发布表单后会调用正确的操作。
-
这很奇怪。我面前有确切的代码。您是否使用了不同的模型绑定器?
-
很奇怪,我也遇到过类似的问题,不知道是什么原因造成的。值 [public ActionResult Create(Text value)] 为 null 的情况相同,但另一个控制器的类似操作可以正常工作。除了 1 个 Guid 属性和 2 个字符串属性之外,该类没有什么特别之处。
标签: asp.net-mvc