views:

59

answers:

3

Hi

I'm looking for a good solution to pass two generic objects to a viewpage like ViewPage

The view should render a Customer, and the SomePresentation holds data used in the view, could be a list of cities where a customer holds one city.

I don't want to use ViewDate["somedata"] for various reasons. So if anybody has a solution to get the second parameter up and run, please let me know.

I read something about using an IPresentationModel, but not sure how to do it

Best regards

+1  A: 

Just pass a class to your view:

public class MyViewData
{
  public string SomeData {get;set;}
}

controller action...

var model = new MyViewData {SomeData = "hello world"};
return View(model);

your view delcaration...

ViewPage<MyViewData>

view itself...

<%=Model.SomeData%>
mxmissile
+2  A: 

Use partial views to render the two different sets of data and use a for view model to return the two different sets of data.

so you could have a form view model like;

public class myData
{
  IQueryable cities {get;set;}
  Customer mycust {get;set;}
}

then fill that object with your data and return it to the view

return View(myData)

then pass the data sets to your partial views

griegs
A: 

If you must use ViewData instead of a model, MVCContrib has a extension to ViewData that gives a strongly-typed interface to the ViewData property.

http://www.codeplex.com/MVCContrib

But the best-practice is the strongly-typed model like the others have suggested.

jayrdub