Reputation: 965
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)
{
}
Upvotes: 1
Views: 5159
Reputation: 965
ended up being the model binder created was looking in the form for the guid on the post rather than the query string
Upvotes: 0
Reputation: 13837
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?
Upvotes: 0
Reputation: 38035
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.
Upvotes: 0
Reputation: 4278
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!
Upvotes: 2