passing parameters to my partial view?

You could pass a model object to the partial (for example a list of strings):

<% Html.RenderPartial("~/controls/users.ascx", new string[] { "foo", "bar" }); %>

Then you strongly type the partial and the Model property will be of the appropriate type:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.Generic.IEnumerable<string>>" %>

<% foreach (var item in Model) { %>
    <div><%= Html.Encode(item) %></div>
<% } %>

Leave a Comment