我正在尝试将privApplicationId(从ViewBag检索)传递给我的控制器中的ActionResult
布局Cshtml页面:
@Html.ActionLink("Comments", "ViewComments", "SubmittedApplications", new { @area = "Privileging" }, new { privApplicationId = @ViewBag.PrivApplicationId })
但是,每次进入ActionResult时,privApplicationId值都为null。
Controller ActionResult:
public ActionResult ViewComments(long? privApplicationId)
你能帮帮我吗?
答案 0 :(得分:1)
从@
删除ViewBag
并将null作为最后一个参数传递。
这应该工作
@Html.ActionLink("Comments",
"ViewComments",
"SubmittedApplications",
new
{
area = "Privileging",
privApplicationId = ViewBag.PrivApplicationId
},
null)
答案 1 :(得分:0)
你选择了ActionLink
助手的错误重载。 new { privApplicationId = @ViewBag.PrivApplicationId }
作为htmlAttribute
参数传递,但应为routeValue
。试试这个:
@Html.ActionLink("Comments", "ViewComments", "SubmittedApplications",
new { area = "Privileging", privApplicationId = @ViewBag.PrivApplicationId }, null)