如何访问 FormCollection、ViewData 和 ModelState
在 ASP.NET MVC 应用程序中运行时,除了直接在视图中工作之外,是否有任何方法可以访问当前正在运行的请求的 FormCollection、ViewData、ModelState 等?我希望能够从视图中调用一些自定义处理程序,但无需传递它们即可访问这些集合。我在想类似于网络表单中的 HttpContext.Current 的东西?
Is there any way to get access to the current running request's FormCollection, ViewData, ModelState, etc. when running in an ASP.NET MVC application other than if you are directly working in the View? I'd like to be able to call some custom handlers from within the view, but access these collections without having to pass them. I'm thinking something similar to HttpContext.Current in webforms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试,
Try,
有一个 ViewContext 对象可以让您链接回您所要求的大部分内容,但您确实必须问自己为什么要在视图中执行所有这些操作。 (无论如何,恕我直言)
编辑:我可能误读了你的问题。控制器中有一个ControllerContext,视图中有一个ViewContext。 MVC 中的大多数扩展点都有某种 Context 对象,可让您获取请求及其数据。
There is a ViewContext object that lets you link back to most of what you're asking for, but you really have to ask yourself why you're doing all of this in the view. (IMHO anyway)
Edit: I may have misread your question. There is a ControllerContext in the controller and a ViewContext in the view. Most of the extensibility points in MVC have some sort of Context object that lets you get at the Request and it's data.