how do you reuse a partial view with setting different ids
Posted
by oo
on Stack Overflow
See other posts from Stack Overflow
or by oo
Published on 2010-04-04T13:10:33Z
Indexed on
2010/04/04
13:23 UTC
Read the original article
Hit count: 384
i have a partial view with a dropdown in it. the code looks like this:
<%=Html.DropDownListFor(x => Model.Exercises, new SelectList(Model.Exercises, "Id", "Name", Model.SelectedExercise), new { @id = "exerciseDropdown", @class = "autoComplete" })%>
the issue is that i want to reuse this partial view in multiple places but i want to have a different id assigned to the control (instead of exerciseDropdown always) but on the outside i only have this . .
<% Html.RenderPartial("ExerciseList", Model); %>
is there anyway to pass in an id into a partial view. is there a standard way to inject the ids into a partial view ?
right now i am doing things like this:
<% Html.RenderPartial("ExerciseList", Model); %>
<% Html.RenderPartial("ExerciseList2", Model); %>
where ExerciseList and ExerciseList2 are identical but with different ids but i am sure there is a better way.
© Stack Overflow or respective owner