【发布时间】:2018-04-12 02:17:31
【问题描述】:
我有一个名为 (Term1score) 的控制器,在控制器内部我有两种不同的操作方法 (Index_Test,EditScore)。
现在在我的 (Index_Test) 的视图中,我有 Html 动作链接,它将重定向到 (Edit Score) 现在我想要的是它会重定向到特定 ID(Example if(Index_Test) SubjectId=1 then it will go to(EditScore) SubjectID=1,)正如您在我的控制器中看到的,它们都针对相同的 SubjectID,关于如何修复的任何想法这?感谢并感谢您的回复..
控制器:
public ActionResult Index_Test(int? id)
{
List<Term1Score> score = db.Term1Scores.Where(x => x.SubjectID == id).ToList();
return View(score);
}
[HttpGet]
public ActionResult EditScore(int? id)
{
List<Term1Score> score = db.Term1Scores.Where(x => x.SubjectID== id).ToList();
return View(score);
}
我试图把它放在 Index_Test 视图中。 这一项工作,但它总是只转到 ID 1 - 如何使这个自动更改?
@Html.ActionLink("Edit", "EditScore", "Term1Score", new { id= "1" }, null
我尝试了一些,但仍然没有。
@Html.ActionLink("Edit", "EditScore", "Term1Score", new { id=@Model.id }, null)
@Html.ActionLink("Edit", "EditScore", "Term1Score", new { testId=testId.id }, null)
@Html.ActionLink("Edit", "EditScore", "Term1Score", new { id= "" }, null)
【问题讨论】:
-
重定向不是正确的术语。重定向是指服务器收到对一个 URL 的请求,然后发送一个响应,指示该请求应再次发送到另一个 URL。您要创建的是指向 URL 的超链接。
标签: c# asp.net-mvc html-helper html.actionlink