基于视图模型的动态视图
我有一个 asp.net mvc 2 应用程序。我需要向每个用户显示相同的页面。但每个用户对数据拥有不同的权利。 IE有的可以查看但不能编辑某些数据,有的不能编辑也不能查看数据。理想情况下,无法查看或编辑的数据是视图上的空白。出于安全原因,我希望我的视图模型尽可能稀疏。我的意思是,如果无法查看或编辑某个字段,则该字段不应位于视图模型上。显然我可以为每个视图模型编写视图,但这似乎很浪费。所以这是我的想法/愿望清单
我可以用属性装饰视图模型并挂钩到 html 助手的预渲染事件并告诉它执行
吗???
我可以让 html 助手输出
来查找在视图模型上找不到的条目吗?
或者
我可以轻松地将内置视图转换为代码,然后以编程方式构建标记,然后放入渲染引擎中进行处理并在客户端以 html 形式查看?
I have an asp.net mvc 2 app. I need to display the same page to each user. But each user has different rights to the data. IE some can see but not edit some data, some cannot edit nor see the data. Ideally data that cannot be seen nor edited is whitespace on the view. For security reasons I want my viewmodels to be sparse as possible. By that I mean if a field cannot be seen nor edited , that field should not be on the viewmodel. Obviously I can write view for each view model but that seems wasteful. So here is my idea/wishlist
Can I decorate the viewmodel with attributes and hook into a pre render event of the html helpers and tell it to do
instead???
Can I have the html helpers output
for entries not found on the viewmodel??
or
can I easily convert a view built into code then programaticlly build the markup and then put into the render engine to be processed and viewd as html on client side??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从你提出问题的方式来看,恐怕任何答案都会导致一个相当复杂的观点。根据用户的角色决定显示哪个视图(以及构建哪个视图模型)是控制器的责任。
编辑1:回复评论
你能做这样的事情吗?
这可以转化为辅助控件。
那么,在你看来,
类似的东西应该有效。
The way you've phrased the question, I'm afraid any answer would result in a quite complex view. Deciding which view to display (and which view model to build) dependent on roles of the user is the responsibility of the controller.
EDIT 1: Response to comment
Could you do something like this?
This could translate into a helper control.
Then, in your view,
Something close-ish to that should work.