asp.net mvc 3模型绑定器不绑定
我有一个登录页面,似乎登录信息没有绑定到我的模型,
@using (Html.BeginForm("LogOn", "Account"))
{
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName, new { style = " width:200px" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password, new { style = " width:200px" })
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}
...
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
Log(new Exception(string.Format("model username : {0}, password : {1}, request[username] {2} , request[password] : {3}", model.UserName, model.Password, Request["UserName"], Request["Password"])));
try
{...
模型信息为空,即使在 firebug 中我可以看到表单已发布
,这只发生在我的产品服务器上,
一次在 本地工作正常过一会儿它就会工作并让您登录
I have a logon page and it seem like the login info is not being bound to my model
@using (Html.BeginForm("LogOn", "Account"))
{
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName, new { style = " width:200px" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password, new { style = " width:200px" })
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}
...
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
Log(new Exception(string.Format("model username : {0}, password : {1}, request[username] {2} , request[password] : {3}", model.UserName, model.Password, Request["UserName"], Request["Password"])));
try
{...
the model info is empty, even though in firebug i can see that the form was posted
this only happens on my prod server, works fine locally
once in a while it will work and let you log in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能
string returnUrl
是令人困惑的绑定器,我认为在您的示例中,您通常需要使用绑定前缀作为模型名称,但它可以是任何字符串,因此您的表单将使用绑定元素名称呈现类似,稍后您可以通过添加操作(方法)参数 BindAttribute 来获取它,如下所示
Probably
string returnUrl
is confusing binder, I think in your exapmple you will need to use binding prefix, usually, as model name, but It can be any string, so your form will be rendered with binding element names likeand later you can fetch it by adding in your action (method) parameter BindAttribute like folowing