我有一个带有下拉列表的部分视图。代码如下所示:
<%=Html.DropDownListFor(x => Model.Exercises, new SelectList(Model.Exercises, "Id", "Name", Model.SelectedExercise), new { @id = "exerciseDropdown", @class = "autoComplete" })%>
问题是我想在多个地方重用这个局部视图,但我想为控件分配一个不同的 id(而不是总是用 exerciseDropdown),但在外面我只有这个:
<% Html.RenderPartial("ExerciseList", Model); %>
反正有没有将 id 传递到局部视图中?是否有将 id 注入局部视图的标准方法?
现在我正在做这样的事情:
<% Html.RenderPartial("ExerciseList", Model); %>
<% Html.RenderPartial("ExerciseList2", Model); %>
其中 ExerciseList 和 ExerciseList2 相同但具有不同的 ID,但我相信有更好的方法。