質問

recently I have been trying to add a link that allows people to delete their own comments on my website. I have followed the advice of the answer of the question asked here. This is what my code looks like now:

@Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" })

Then I have the controller handle the values here:

public ActionResult DeleteComment(int commentID, string actionReturnName)
{
    DB.CommentDB.DeleteComment(commentID);

    return RedirectToAction(actionReturnName);
}

This seems to be the right way to do it, but what am I doing wrong? I keep getting this error

Server Error in '/' Application.

The parameters dictionary contains a null entry for parameter 'commentID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DeleteComment(Int32, System.String)'

I might be missing something really stupid, but if you could help me that would be great!

役に立ちましたか?

解決

You're using the wrong overload. Right now you're passing in your routeValues as the htmlAttributes.

Pass in an extra null as the htmlAttributes to call the correct method.

@Html.ActionLink("x","DeleteComment", "Videos", new { commentID = 1234, actionReturnName = "[action]" }, null)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top