Thursday, April 21, 2011

How to pass MVC User Controls Different Data

I have a user control I use multiple times on a page. It uniformly formats some object "X" and allows certain interactions. What I'd like to do is to pass a separate object to each separate instance of the user control. I'm currently rendering the controls as below, and just depending on some specific ViewData being set. I'd like to make it more generic than that.

<% Html.RenderPartial("Vignet"); %>
From stackoverflow
  • Use a strongly typed partial view, and pass the model explicitly:

    <% Html.RenderPartial("Vignet", Model.VignetData); %>
    

0 comments:

Post a Comment