0
votes

On my Index page I have the following link to the Details view:

 @Html.ActionLink("Details", "Details", new { id = item.ClubId })|

My controller is expecting an int:

public ActionResult Details(int ClubId)
{
    var club = _service.GetClub(ClubId);
    var model = AutoMapper.Mapper.Map<ClubViewModel>(club);
    return View(model);
}

Im getting this every time though:

The parameters dictionary contains a null entry for parameter 'ClubId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'MyProject.Web.Controllers.ClubsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

I know this is something to do with routing however I have tried swapping UrlParameter.Optional to "" and making the ViewModel's ClubId nullable but the error remains.

If I rewire my controller to accept a Club object and pass in item from the Index view then everything is fine and the ClubId is populated in debug but I'm left with a stupidly large parameter list in the URL.

I don't really get what the problem is here?

2
have you tried using ClubId instead of just id? - oskar132
For gods sake, thanks - JsonStatham
There is a difference between /url/parameters and ?query=string&parameters. The former affects the routing, the latter does not. - Andrei
would you mind marking mine as the answer? Thanks a lot :D - oskar132

2 Answers

2
votes

Your controller is expecting a parameter named ClubId but you're passing a parameter called id. They need to match.

1
votes

have you tried using ClubId instead of just id?