HTML 表单回发后隐藏字段不会更新
@Html.HiddenFor(model => model.JobIndicator)
提交页面后,JobIndicator 的值不会刷新。
当我将其显示在显示字段中时,我可以看到该值正在更新。
@Html.HiddenFor(model => model.JobIndicator)
The value for JobIndicator doesn't get refreshed after submitting the page.
I can see the value getting updated when I have it in the display field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将其放入您的控制器中:
然后您的隐藏字段将被更新。
Put this in your controller :
Then your hidden field will be updated.
问题是 Html 帮助程序从
ModelState
获取数据,而不是从您调用 post 操作时传递的模型。要解决此问题,您可以调用 < code>ModelState.Clear() 在返回视图之前的 post 操作中,这样,一旦视图重新生成,ModelState
中的信息将被清除并重新填充。您可以在此 博客
The problem is Html helpers get data from
ModelState
and not from model you pass when you call post action.To solve this, you can callModelState.Clear()
in the post action before you return your view, this way the info in theModelState
is going to be cleared and repopulated once your view is regenerated.You can find more info about this issue (and other solutions) in this blog
我自己也遇到了这个问题。一个解决方案(尽管并不优雅)是为此使用基本的 HTML 语法并使用模型的值。
Ran in to this issue myself. A solution (though not elegant) is to use the basic HTML syntax for this and use the model's value.
而不是...
如果您将变量包含在一个对象中,它将按预期工作。
看来只有那顶级了。
Instead of having...
if you enclose the variable in an object it will then work as expected.
It Only seems to be that top level.
只需确保将此行放在表单标记内即可
Just make sure to put this line inside the form tag