Asp.net mvc MVC4中的ActionLink无法解决控制器中的操作
我有一个带有一些动作的学生控制器当我想链接控制器的动作时,我的视图找不到我的动作的名称 因此,您可以看到我的控制器的操作:Asp.net mvc MVC4中的ActionLink无法解决控制器中的操作,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我有一个带有一些动作的学生控制器当我想链接控制器的动作时,我的视图找不到我的动作的名称 因此,您可以看到我的控制器的操作: namespace EducationMVC.Controllers { [Authorize] public class StudentController : Controller { // // GET: /Student/ private StudentRepositor obj = new
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>
找不到ScheduleStudentList操作。它只找到索引并删除和编辑操作。那么我应该怎么做
致以最诚挚的问候试试这个
@Html.ActionLink("لیست دانشجویان ","ScheduleStudentList","Student", new { id=item.id })
您不必指定控制器关键字。希望有帮助
看看帖子,试试这个
@Html.ActionLink("لیست دانشجویان ","ScheduleStudentList","Student", new { id=item.id })
您不必指定控制器关键字。希望有帮助
看看post,正如Mauro提到的,您没有指定控制器。然而,当您提供控制器名称时,您需要一个额外的null来清除您正在调用的重载
@Html.ActionLink("لیست دانشجویان ", "ScheduleStudentList", "Student", new { id=item.id }, null)
您遇到此问题是因为如果没有额外的null,您正在呼叫:
本质上,您的学生将进入routevalues参数,而不是被解释为字符串。生成的链接的结尾可能有?length=7这样的内容,因为它误解了这个参数
添加附加的null将更改它,以便您调用:
正如Mauro提到的,您没有指定控制器。然而,当您提供控制器名称时,您需要一个额外的null来清除您正在调用的重载
@Html.ActionLink("لیست دانشجویان ", "ScheduleStudentList", "Student", new { id=item.id }, null)
您遇到此问题是因为如果没有额外的null,您正在呼叫:
本质上,您的学生将进入routevalues参数,而不是被解释为字符串。生成的链接的结尾可能有?length=7这样的内容,因为它误解了这个参数
添加附加的null将更改它,以便您调用:
代码的问题是没有使用@Html.ActionLink的任何有效重载。 尝试:
@ActionLinkلیسد㶕شوی㶋ن,ScheduleStudentList,Student,new{id=item.id},如其他人所建议的那样为空,应该可以工作 代码的问题是您没有使用@Html.ActionLink的任何有效重载。 尝试:
@ActionLinkلیسد㶕شوی㶋ن,ScheduleStudentList,Student,new{id=item.id},如其他人所建议的那样为空,应该可以工作 在浏览器中查看时,它在页面上生成的链接是什么?在浏览器中查看时,它在页面上生成的链接是什么?是否有作为第二个参数的路由参数?你通过模型正确吗?你应该看看这个方法的定义。。。签名可能有问题。是否有作为第二个参数的路由参数?你通过模型正确吗?你应该看看这个方法的定义。。。签名可能有问题。因此,当我将其更改为student时,它不起作用,但当我添加一些选项(如add Null)时,它起作用,为什么?我的问题是什么?更新了答案以包含解释。因此,当我将其更改为student时,它不起作用,但当我添加一些选项(如add Null)时,它起作用,为什么?我的问题是什么?更新了答案,添加了解释
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
string controllerName,
Object routeValues,
Object htmlAttributes
)