views:

55

answers:

2

I have this code in my view:

<%=Html.ActionLink("Approve", "NewsApprove", New With {ID}, DBNull.Value)%>

in my controller:

Function NewsApprove(ByVal dID As Integer) As ActionResult
    dTempNews.ApproveNews(dID)
    Return RedirectToAction("Administrator")
End Function

My problem is that it always return an error that says: The parameters dictionary contains a null entry for parameter 'dID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult NewsApprove(Int32)' in 'UC_Website.UserController'. To make a parameter optional its type should be either a reference type or a Nullable type.

But I don't see any problem with the code. I think this is a simple problem but i can't figure out how to make it work.. Help please. Thank you!

+1  A: 

I have not worked on asp.net MVC. But, here is my understanding.

Look at the link that gets generated for <%=Html.ActionLink("Approve", "NewsApprove", New With {ID}, DBNull.Value)%>. Does it look like http://.../Approve/? (i.e without any ID parameter)

Either you should pass in a valid integral value for the action to execute. i.e the link should look like http://.../Approve/0123

For that, you should pass in a valid integral value & not null value.
It seems the code should be new with {"dID", ID}, I guess.

OR

Let the NewsApprove method accept Nullable<int> if a link without the ID parameter is fine.
(e.g. http://.../Approve/)

EDIT: Is the NewsApprove method overloaded? i.e 1 with an integer parameter & another method with same name, but no parameters.

shahkalpesh
it does return the right linkhttp://.../User/NewsApprove/1but with error..i've put a breakpoint in the function but seems that it gives me the right link but doesn't pass through the function NewsApprove..
tiff
when i didn't put a parameter, it worked just fine..
tiff
it's not overloaded..i think it should work even if it's not overloaded? :D
tiff
A: 

View:

<%=Html.ActionLink("Approve", "NewsApprove", New With {ID}, DBNull.Value)%>

Controller:

Function NewsApprove(ByVal ID As Integer) As ActionResult
    dTempNews.ApproveNews(ID)
    Return RedirectToAction("Administrator")
End Function

the parameter name should be the same as the name of the value you're trying to call..

tiff