Ajax.ActionLink不调用控制器操作及其视图

时间:2016-09-28 12:16:20

标签: ajax asp.net-mvc-4

此处,actionlink' Get Students'在TeacherIndex的{​​{1}}视图中,必须调用TeacherController和操作方法StudentController,然后转到视图StudentList

TeacherController中的

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

1 个答案:

答案 0 :(得分:3)

参数名称应相同。用这个:

@Ajax.ActionLink("Get Students", "StudentList", "Student", new { @TeacherId = item.TeacherId }, new AjaxOptions { HttpMethod = "POST" })