此处,actionlink' Get Students'在TeacherIndex
的{{1}}视图中,必须调用TeacherController
和操作方法StudentController
,然后转到视图StudentList
。
TeacherIndex.cshtml:
StudentIndex
StudentController:
@model IEnumerable<StudentMVC.Models.TeacherEntity>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.TeacherId)
</th>
...
</tr>
@if (Model != null)
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.TeacherId)
</td>
...
<td>
@Ajax.ActionLink("Get Students", "StudentList", "Student", new { id = item.TeacherId }, new AjaxOptions { HttpMethod = "POST" })
</td>
</tr>
}
}
但是在这里,而不是那个,显示
&#39; /&#39;中的服务器错误应用。无法找到该资源。
请求的网址:/ Student / StudentList / 1
答案 0 :(得分:3)
参数名称应相同。用这个:
@Ajax.ActionLink("Get Students", "StudentList", "Student", new { @TeacherId = item.TeacherId }, new AjaxOptions { HttpMethod = "POST" })