HTML 标记和ASP.NET MVC3
我希望将部分网页提供给客户端页面。而不是让它们在每个网站上都是静态的。我的网站在页面的某些部分有重复出现的标记,例如横幅、导航。在某些网站中,我需要稍微自定义标记。所以如果可能的话我需要能够延长。
有人可以告诉我 MVC3 是否是解决这个问题的理想方案吗?我正在思考片面的观点。你能继承吗?扩展局部视图?
谢谢
I have parts of the web page which I would like MVC3 to serve to client pages. Instead of making them static in everysite. I have sites which have reoccurring markup in parts in the page, such as banner, navigation. In some sites I will need to customize the markup a little. So I need to be able to extend if possible.
Can someone please tell me if MVC3 is ideal as a solution to this? I am thinking partial views. Can you inherit & extend partial views?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以根据您的需要实施部分视图。例如,您可以按如下方式使用它们:
在视图内,您可以按如下方式调用此部分视图:
您几乎可以将任何内容作为
Model
传递给部分视图。如果您计划在多个应用程序上使用这些部分视图,我鼓励您为这些部分视图创建 Nuget 包,并通过 Nuget 包管理器将它们放入每个应用程序中。
Partial Views can be implemented for your needs. For example, you can use them as follows :
Inside a view, you can call this partial view as follows :
You can pretty much pass anything to partial view as
Model
.If you plan to use those partial views on multiple applications, I encourage you to create Nuget package for those Partial Views and get them into each application through Nuget Package Manager.
横幅、导航、自定义面板等 - 所有这些都是您可能希望随着时间的推移添加、组合、删除或更新的组件。是的,部分观点很容易完成这项工作,但在我看来,继承并不是前进的道路。
您的部分视图应该基于视图模型。例如:OrderPanelViewModel、UserMenuViewModel、CustomPanelViewModel。每个部分视图现在都是一个组件,一个您可以根据需要添加、删除、修改的功能。
如果您想组合横幅和用户菜单会发生什么?如果它们继承自相同的视图模型,则它将不起作用,但如果它们有自己的视图模型,则它将起作用。
例如:
您现在可以基于此视图模型创建视图
Banners, navigation, custom panels etc - all these are the components that you might want to add, combine, remove or update as time goes. Yes, partial views would do the job easily, but in my opinion, inheritance isn't a way forward.
Your partial views should be based on view models. For example: OrderPanelViewModel, UserMenuViewModel, CustomPanelViewModel. Each partial view is now a component, a feature that you can add,remove, modify as you feel suited.
What happens if you want to combine banner and a user menu? It's not going to work if they inherit from the same view model, but it will work if they have their own view models.
For example:
You can now base your view on this view model