我有一个学生Model.This模型在其控制器中有这样的功能:
public ActionResult Index()
{
var model = obj.GetStudentlist();
return View(model);
}
public ActionResult ScheduleStudentList(string id)
{
var model = obj.GetStudentlistOfSchedule(id);
return View(model);
}
所以索引控制器会返回一个包含所有学生的列表,但 ScheduleStudentList 控制器会再次返回具有特定ID的学生列表。
所以我的问题是我有索引控制器的视图,我想将 ScheduleStudentList 列表传递给索引的视图。因为这两个控制器都返回相同的模型。我该怎么办?
我的索引视图代码:
@model IEnumerable<DomainClasses.Student>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.IntNo)
</th>
<th>
@Html.DisplayNameFor(model => model.FatherName)
</th>
<th>
@Html.DisplayNameFor(model => model.BirthLocation)
</th>
<th>
@Html.DisplayNameFor(model => model.Birthday)
</th>
<th>
@Html.DisplayNameFor(model => model.ImageUrl)
</th>
<th>
@Html.DisplayNameFor(model => model.Major)
</th>
<th>
@Html.DisplayNameFor(model => model.Degree)
</th>
<th>
@Html.DisplayNameFor(model => model.IdentNo)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th>
@Html.DisplayNameFor(model => model.Mobile)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Password)
</th>
<th>
@Html.DisplayNameFor(model => model.RegisterDate)
</th>
<th>
@Html.DisplayNameFor(model => model.State)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.IntNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.FatherName)
</td>
<td>
@Html.DisplayFor(modelItem => item.BirthLocation)
</td>
<td>
@Html.DisplayFor(modelItem => item.Birthday)
</td>
<td>
@Html.DisplayFor(modelItem => item.ImageUrl)
</td>
<td>
@Html.DisplayFor(modelItem => item.Major)
</td>
<td>
@Html.DisplayFor(modelItem => item.Degree)
</td>
<td>
@Html.DisplayFor(modelItem => item.IdentNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mobile)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Password)
</td>
<td>
@Html.DisplayFor(modelItem => item.RegisterDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.State)
</td>
<td>
@Html.DisplayFor(modelItem => item.StudentId)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
最好的问候
答案 0 :(得分:3)
只需返回
即可使用索引视图return View("Index", model);
来自您的ScheduleStundentList(字符串ID)方法。