views:

877

answers:

1

I have created a table in the database that has a System.Guid as it's primary key. The required ADO.Net Entity Framework model has been generated and the required stored procedures has been mapped.

I created a new controller and added the basic required code for Create and Edit for the data. However when the clicking on the link to edit the a particular record the following error is generated:

The parameters dictionary contains a null entry for parameter '[MyId]' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Edit(System.Guid)' in '[MySite].[MyController].[SpecificController]'. To make a parameter optional its type should be either a reference type or a Nullable type. Parameter name: parameters

The edit action is declared in the controller as follows:

public ActionResult Edit(Guid itemId)
{
    return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(MyItem itemToModify)
{

}

When adding a new record the new Guid is generated via a Stored Procedure and the list is displaying the correct Guid. The Url is also passing the correct Guid for retrieval.

I can't seem to capture the point at which this fails, but how would I go about passing a System.Guid as a parameter to the Controller?

+8  A: 

Unless you've updated your routes, it is expecting (by default) the final parameter in a route to be named "id". That is, if you have a route like /specific/edit/5646-0767-..., it will map the guid into the route value dictionary with key "id" regardless of what the parameter on your method is named. I'd follow this convention and change the method definition to:

public ActionResult Edit(Guid id)

You can get around this, by explicitly specifying the name of the route parameter, but then you end up with a url that looks like: /specific/edit?itemid=5646-0767-...

tvanfosson
Now I feel stupid for asking :(
Diago
Don't worry about it -- the only reason I knew the answer is I did the same thing once and had to figure it out.
tvanfosson