views:

327

answers:

4

url : /jobs/UpdateJobResults/GUIDHERE

When I do a post to the below function the guid id is always blank, can I use the above format to POST the GUID in the url (as the form body has the results dictionary) ?

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateJobResults(Guid Id, Dictionary<string, object> results)
{

}
A: 

Yes, the 3rd parameter of the default route is id. In most of the examples that is an integer, but a Guid should work.

Did you try it with the id parameter as a string instead of a Guid? Normally MVC is smart enough to give you the type of object you're looking for, but I haven't tried it with a Guid. Expecting id to be a string might work. Then at least you'd know your routing was working.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateJobResults(string id, Dictionary<string, object> results)
{

}

Are you using the default route or have you set up your own routes?

Edit: So, you're using your own routes. Please edit your question to include those. Also, you say it works for the GET, but not for the POST. What does your action look like that is hit with the GET request? I think we're going to need more information in order to help with this one. Are you sure the client requests contain the Guid in the url?

Dennis Palmer
own routes and using model binder to cast the guid, it works fine on GET requests but not for POST, its ASP.NET MVC REST if that makes any difference
monkeylee
A: 

You can try revising your Html.BeginForm by passing this as a route value...

Html.BeginForm("myAction", "myController", new { Id = myGuid });

Obviously where myGuid is your param.

If your routing is setup correctly, MVC will know to post your form with this value in the URL (and/or querystring) rather than in the Request.Form data...

Good luck!

Funka
P.S., if this doesn't work, please post the route you're using for this action to see if that might help...
Funka
That's just a different way of building the target url for the form. It will generate the same url as the OP said he was using.
Dennis Palmer
I've using MVC REST so there is not html form post as from a client app
monkeylee
A: 

I believe that MVC uses Convert.ChangeType for conversions. This method does not support Guids. My recommendation would be to change the parameter to a string and convert it in the method.

Brian
A: 

ended up being the model binder created was looking in the form for the guid on the post rather than the query string

monkeylee