Question

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!

Était-ce utile?

La solution

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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top