Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 pass @model to partial view

I have two partial views which are exactly the same, but for the @model.

@model Project.Models.X

@model Project.Models.Y

How could I pass this model type to the view so that I can use the same view for both?

like image 796
TheGwa Avatar asked Jun 21 '11 13:06

TheGwa


1 Answers

Not sure if this is best practice, but you could also use HTML.RenderAction to call your controller and have it return a PartialViewResult with whatever model you want, like so:

  @{Html.RenderAction("MyPartialAction", "MyController", new { someID = 1 });}

and

 public PartialViewResult MyPartialAction(int? someID)
 {
        return PartialView("MyPartial",SomeModel);
 }
like image 195
mymex1 Avatar answered Sep 23 '22 21:09

mymex1