我有一個學生控制器,當我想要鏈接控制器的動作時,我的視圖無法找到我的動作名稱。MVC4中的ActionLink無法解決控制器中的操作
所以你可以看到我的控制器的動作:
namespace EducationMVC.Controllers
{
[Authorize]
public class StudentController : Controller
{
//
// GET: /Student/
private StudentRepositor obj = new StudentRepositor();
public ActionResult Index()
{
var model = obj.GetStudentlist();
return View(model);
}
public ActionResult ScheduleStudentList(string id)
{
var model = obj.GetStudentlistOfSchedule(id);
return View("Index",model);
}
public ActionResult Create()
{
return View("Create");
// return View();
}
[HttpPost]
public ActionResult Create(Student student)
{
student.RegisterDate = DateTime.Now.Date;
obj.AddNewStudent(student);
obj.Save();
return RedirectToAction("Index", "Student");
}
public ActionResult Edit(int id)
{
return View(obj.FindStudentById(id));
}
[HttpPost]
public ActionResult Edit(Student student)
{
if (ModelState.IsValid)
{
obj.Update(student);
obj.Save();
}
return RedirectToAction("Index", "Student");
}
public ActionResult Delete(int id)
{
obj.RemoveStudent(obj.FindStudentById(id));
obj.Save();
return RedirectToAction("Index", "Student");
// return View();
}
}
}
這是我的觀點:
@model IEnumerable<EducationMVC.Models.SchedulePresentation>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.teacherName)
</th>
<th>
@Html.DisplayNameFor(model => model.lessonName)
</th>
<th>
@Html.DisplayNameFor(model => model.className)
</th>
<th>
@Html.DisplayNameFor(model => model.degreeName)
</th>
<th>
@Html.DisplayNameFor(model => model.facultyName)
</th>
<th>
@Html.DisplayNameFor(model => model.semesterName)
</th>
<th>
@Html.DisplayNameFor(model => model.majorName)
</th>
<th>
@Html.DisplayNameFor(model => model.DateOfExam)
</th>
<th>
@Html.DisplayNameFor(model => model.Capacity)
</th>
<th>
@Html.DisplayNameFor(model => model.examLocation)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.teacherName)
</td>
<td>
@Html.DisplayFor(modelItem => item.lessonName)
</td>
<td>
@Html.DisplayFor(modelItem => item.className)
</td>
<td>
@Html.DisplayFor(modelItem => item.degreeName)
</td>
<td>
@Html.DisplayFor(modelItem => item.facultyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.semesterName)
</td>
<td>
@Html.DisplayFor(modelItem => item.majorName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfExam)
</td>
<td>
@Html.DisplayFor(modelItem => item.Capacity)
</td>
<td>
@Html.DisplayFor(modelItem => item.examLocation)
</td>
<td>
@Html.ActionLink("ویرایش", "Edit", new { id=item.id }) |
@Html.ActionLink("حذف", "Delete", new { id=item.id })|
@Html.ActionLink("لیست دانشجویان ","ScheduleStudentList","StudentController", new { id=item.id })
</td>
</tr>
}
</table>
所以你可以在視圖中看到的最後一行:
@Html.ActionLink("لیست دانشجویان ","ScheduleStudentList","StudentController", new { id=item.id })
可以't找到ScheduleStudentList action.It只找到index and delete and edit action's .so我該怎麼辦?
問候
在瀏覽器中查看時頁面上生成的鏈接是什麼? –