Asp.net mvc html.actionlink路由值错误
最近我一直在尝试添加一个链接,允许人们删除自己在我的网站上的评论。我已按照问题答案的建议行事。这就是我的代码现在的样子:Asp.net mvc html.actionlink路由值错误,asp.net-mvc,razor,actionlink,routevalues,Asp.net Mvc,Razor,Actionlink,Routevalues,最近我一直在尝试添加一个链接,允许人们删除自己在我的网站上的评论。我已按照问题答案的建议行事。这就是我的代码现在的样子: @Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" }) 然后我让控制器在这里处理值: public ActionResult DeleteCo
@Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" })
然后我让控制器在这里处理值:
public ActionResult DeleteComment(int commentID, string actionReturnName)
{
DB.CommentDB.DeleteComment(commentID);
return RedirectToAction(actionReturnName);
}
这似乎是正确的做法,但我做错了什么?
我一直在犯这个错误
“/”应用程序中出现服务器错误。
参数字典包含方法“System.Web.Mvc.ActionResult DeleteComment(Int32,System.String)”的非空类型“System.Int32”的参数“commentID”的空条目
我可能错过了一些非常愚蠢的事情,但如果你能帮助我,那就太好了 您使用了错误的重载。现在您正在将RouteValue作为HtmLatAttributes传递 作为htmlAttributes传入一个额外的null以调用正确的方法
@Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" }, null)
你使用了错误的过载。现在您正在将RouteValue作为HtmLatAttributes传递 作为htmlAttributes传入一个额外的null以调用正确的方法
@Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" }, null)