views:

25

answers:

1

I'm using the MVCContrib Grid. My controller action accepts 3 parameters, the sortoptions and paging parameter for the grid, and a ResourceID parameter, that specifies which resource you want to view bids for.

When i click on the links i get the following error

The parameters dictionary contains a null entry for parameter 'ResourceId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ByResource(Int32, MvcContrib.UI.Grid.GridSortOptions, System.Nullable`1[System.Int32])' in 'TaskingApp.Controllers.BidController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.

How do i pass in the ResourceId Parameter in properly?

Here is my Controller action

//Get bids by resource
    public ActionResult ByResource(int ResourceId,GridSortOptions sort, int? page)
    {
        var bids = bidRepo.GetUpcomingBidsByResource(ResourceId);

        if (sort.Column != null)
            bids = bids.OrderBy(sort.Column, sort.Direction);
        ViewData["sort"] = sort;
        return View("Index", bids.AsPagination(page ?? 1, 15));

    }

And here's the actionlink

<%= Html.ActionLink(item.ResourceName, "ByResource", new { id = item.ResourceID })%>
A: 

The specified property must match the controllers property name:

new { ResourceId = item.ResourceID }

That, or change your method signature to the following:

ByResource(int id, GridSortOptions sort, int? page)
GenericTypeTea
Good spot, and i've changed it, but it's not fixed the problem.
Doozer1979
And you get the error when clicking the action link?
GenericTypeTea
Working now after following your second suggestion., and also i've just realised that your first suggestion would have worked too, if i'd followed it properly, so please ignore my earlier comment
Doozer1979
Ah good, so all sorted?
GenericTypeTea
Yep, so for clarity just in case any other mvc noobs have the same problem, i was passing in a parameter called id into the controller action when i should have been passing in ResourceId
Doozer1979