Action method expected parameter named Id and nothing otherwise

Posted by codingbiz on Stack Overflow See other posts from Stack Overflow or by codingbiz
Published on 2012-09-01T09:31:09Z Indexed on 2012/09/01 9:38 UTC
Read the original article Hit count: 178

Filed under:
|
|

The Error

The parameters dictionary contains a null entry for parameter 'UserId' of non-nullable type 'System.Int64' for method 'System.Web.Mvc.ActionResult Predict(Int64)' in 'sportingbiz.Controllers.PredictionController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

This does not work. Throws the error mentioned above

http://mysite/User/Profile/15

This works

http://mysite/User/Profile/?UserID=15

The Controller Action

public ActionResult Profile(long UserID)
{

}

When I changed the parameter name to Id it works. I think it's because Id was specified in the route collection (Global.asax). Is it possible to tell MVC that UserId should map to Id without changing it in the Global.asax

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc