0
我有一個局部視圖,我傳遞了模型名稱來填充它,有沒有任何方式來傳遞模型名稱作爲基於控制器行爲執行的參數?傳遞模型名稱作爲參數
<div id = "Details" >
<% List<Freshmen>() = model based on controller action executed %>
<% using (Html.BeginForm("FreshmenDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("FreshmenDetails", new List<Freshmen>()); %>
<% } %>
</div>
控制器動作:
public ActionResult FreshmenDetails(string id)
{
DataContext Student = new DataContext();
var FreshmenDetails = Student.Freshmen.Where(a => Convert.ToInt64(a.Id) == Convert.ToInt64(id)).ToList();
return PartialView("FreshmenDetails", FreshmenDetails);
}
我必須每3個以上操作的SophomoreDetails(),JuniorDetails(),SeniorDetails()
目前我顯示局部視圖這樣的:
<div id = "Details" >
<% using (Html.BeginForm("FreshmenDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("FreshmenDetails", new List<Freshmen>()); %>
<% } %>
<% using (Html.BeginForm("SophomoreDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("SophomoreDetails", new List<Sophomore>()); %>
<% } %>
<% using (Html.BeginForm("JuniorDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("JuniorDetails", new List<Junior>()); %>
<% } %>
<% using (Html.BeginForm("SeniorDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("SeniorDetails", new List<Senior>()); %>
<% } %>
</div>
我想要類似於:
<div id = "Details" >
<% using (Html.BeginForm("FreshmenDetails", "Students")) %>
<% { %>
<% Html.RenderPartial("FreshmenDetails", new List<Freshmen>()); %>
<% } %>
</div>
你的目標是? – Pluc
發佈你的模型和你的控制器動作。 – ataravati
@Pluc我有多個部分視圖顯示在相同的位置,但有不同的控制器,動作和模型。我能夠參數化Controller和Action的名字,但是在參數化模型中掙扎,尋找一種將這些傳遞給局部視圖的有效方法。這可以實現嗎? – user793468