白名单模型绑定似乎不适用于复杂的属性
我有一个如下所示的 POST 操作:
public ActionResult Create([Bind(Include="userrole,credentials.emailAddress,credentials.password")]User u, string confirmPassword, bool agreeToTerms)
我正在使用默认模型绑定器,并且凭据是我的 User 对象上的属性。 凭证有两个字段(电子邮件地址和密码)。 如果我删除白名单,凭证对象就会被绑定,一切都会按预期工作。 但是,如果我提供该白名单,则用户角色会被绑定,但复杂属性上的电子邮件和密码不会被绑定。 我检查了表单值,他们很关心我列出了它们并且它们与我的对象匹配。
我错过了什么吗?
I have a POST action that looks like this:
public ActionResult Create([Bind(Include="userrole,credentials.emailAddress,credentials.password")]User u, string confirmPassword, bool agreeToTerms)
I'm using the default model binder and credentials is a property on my User object. Credentials has two fields (emailAddress & password). If I remove the Whitelist, the credentials object gets bound and everything works as expected. However, if I provide that whitelist, userrole gets bound but the email and password on the complex property does not. I checked the Form values and they care coming across as I have them listed and they match my object.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您早在二月份就问过这个问题,但如果它仍然有效,您是否将两个文本框指定为:
<%= Html.TextBoxFor(x => x.credentials.emailAddress) %>
,<%= Html.TextBox("credentials.emailAddress") %>
或类似的东西?关键是您需要确保您的文本框设置有
credentials
前缀。I know you asked this question back in February, but if it's still valid, have you specified both your textbox's as:
<%= Html.TextBoxFor(x => x.credentials.emailAddress) %>
,<%= Html.TextBox("credentials.emailAddress") %>
or something similar?The key point being you need to ensure your textbox's are setup with the
credentials
prefix.