获取控制器中隐藏字段的值 (ASP.NET MVC)
我可以达到控制器操作中隐藏字段的值吗?又如何呢?我是否以某种方式将其放入模型中?
谢谢
编辑:一些代码示例如何在隐藏字段中存储某些内容并在回发时检索它将不胜感激。
Can I reach the value of hidden fields in controller action ? And how ? Do I put it in the model somehow ?
Thank you
EDIT: some code example how to store something in hidden field and retrieve it on postback would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您执行发送到服务器的 POST 操作时,隐藏字段就像任何其他表单字段一样。除了在浏览器中的显示(或者更确切地说,缺乏显示)之外,没有什么能让它们变得特别。因此,它们的访问方式应该与您当前访问其他表单字段的方式大致相同。
您目前如何访问其他表单字段?如果它们只是映射到传递到控制器操作的模型,那么隐藏字段应该同样可映射。
相反,您应该能够从 HttpContext 和 Request 对象手动访问任何 HTTP POST 数据。
Hidden fields are just like any other form fields when you get to the POST action being sent to the server. There's nothing that makes them special outside of their display (or lack thereof, rather) in the browser. Thus, they should be accessible in much the same way you currently access other form fields.
How do you currently access other form fields? If they're just mapped to a model which is being passed into the controller action, then hidden fields should be mappable just the same.
Conversely, you should be able to manually access any HTTP POST data from HttpContext and the Request object.