开发者

Building pages with multiple views

开发者 https://www.devze.com 2022-12-11 00:21 出处:网络
I\'m looking to build an ASP.NET MVC application where many screens will have multiple distinct views. Ideally the user would be able to bring the items they require into their workspace page in a por

I'm looking to build an ASP.NET MVC application where many screens will have multiple distinct views. Ideally the user would be able to bring the items they require into their workspace page in a portal style. Even if that is not possible, there would need to be a number of common items joined in various ways for various classes of user: something difficult to achieve with traditional inheritance.

It seems to me that the URL structure allows for only one controller to instantiated and for this to bring up one view at a time (and only one) - not place multiple views on a page. Searching here I have seen reference to MVC Contrib subcontrollers, but I can't see them on the http://www.codeplex.com/MVCContrib site to check them out any further?

Would subcontrollers be the way to go ? If so, where do 开发者_JS百科I find them now. If not, what would you suggest ?


If you want to stick with using asp.net mvc then you can work with partial views which will/should give you the "web part" type functionality which it sounds like you want. You can then limit the which partial views you want to see depending on permissions etc. on the main page views (this could be exposed via a base controller class or something).

I've done a little searching and have come up with a few links which you might find useful ...

Jeffrey Palermo - Talks about templating partial views

Rob Conery - using user controls with asp.net mvc

mikesdotnetting.com - ASP.NET MVC Partial Views and Strongly Typed Custom ViewModels (not read all of this, but it looks pretty usefu)

Hope this helps.


Take a look at the futures assembly and it's implementation of RenderAction(). Although it's not pure MVC, these can basically be used as widgets. They are called from a view and go through a separate controller which then renders a partial view. This sounds like what you may be looking for.

Here's an example...

//Various view data

<div id="user-info">
    <% Html.RenderAction("UserInfo"); %>
</div>

//Rest of view data

This will look for an action method named "UserInfo" on the current controller. That controller can then do what it need to do, and send it's results to a partial view that will be rendered in place of the Html.RenderAction().


Controllers are not bound to any particular views. Depending on your business logic, a controller/action can display any view you want.

EDIT You could always try writing HtmlHelpers and partial views. These are what you should use instead of webforms' server controls and user controls respectively.


Sounds like you are taking about 2 different things:

  • Adding items on the page is web parts not asp.net mvc
  • There is no problem using a controller to choose which view to show, but only one can be shown at a time.

EDIT

What you are looking to do requires both sharepoint and asp.net mvc. It is possible to combined these, see: Using Asp.Net MVC with SharePoint

0

精彩评论

暂无评论...
验证码 换一张
取 消