該URL設法解析例如, 「mylink/Index/1」,但它沒有在我的下一行讀取我的ID。如何從我的控制器獲取htmlAction ID?
@Html.ActionLink("Submit school rating", "Index", "Review", new { id = Model.School_Code }, new { name = "Index" })
控制器(審查模式)
public ActionResult Index(int? id, ReviewSearch model)
{
reviews = revGateway.SelectAll();
if (id == 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
reviews = reviews.Where(s => s.School_Code.Equals(id));
if (reviews == null)
{
return HttpNotFound();
}
var pageIndex = model.Page ?? 1;
model.SearchResults = reviews.ToPagedList(pageIndex, RecordsPerPage);
return View(model);
}
查看(辦學模式)
@Html.ActionLink("Submit school rating", "Index", "Review", new { id = Model.School_Code }, new { name = "Index" })
是什麼讓你覺得id參數沒有綁定。根據你所顯示的代碼,id'Model.School_Code'的值是一個有效的'int',那麼它將被正確綁定。 –