开发者

Null Entry Error

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(开发者_Go百科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!


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.


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜