views:

255

answers:

2

I got a view that inherits : System.Web.Mvc.ViewPage<IEnumerable<MyProjects.Models.MyAccountWrapper>>

In this view I list data about the object MyAccountWrapper. This object contains a list of Account. Like this MyAccountWrapper.Accounts

What I would like in this view is to be able to create an account.

So I Try <% Html.RenderPartial("../Account/Create"); %>

But I got error about is not the good model. How can I deal with that ?

+1  A: 

I suggest that you create a new controller and view that corresponds to "../Account/Create". This pins the URL for that action to a specific view. The user will perceive this as a separate and distinct action, which in fact it is. You can then return them to where they were by using a ReturnUrl technique, if you wish.

In other words, you need a brand new page for this.

Robert Harvey
+1 @Melursus, this is the prefered approach and essentially how an MVC project works. Seperation of concerns is a big factor in an MVC site. You can avoid page bloat by using Partial Views and share them across the different actions.
griegs
The problem is I can't do that because it's in the spec. The designer design the page like what I describe and I have no choice.
Melursus
+3  A: 

Try passing the appropriate model as second parameter when calling RenderPartial.

baretta
Do you have an example or a link of what you propose ?
Melursus
RenderPartial has an overload that allows you to pass the model as the second parameter. It should be showing up in your intellisense.
Robert Harvey
Html.RenderPartial("../Account/Create", (IEnumerable<MyProjects.Models.MyAccountWrapper>)ViewData["Accounts"]); Where you have passed in the MyAccountWrapper into the View via ViewData
theouteredge