U4-2313 - MVC - Posting to surface controller with a route value called 'id' causes exception

Created by Kevin Lawrence 03 Jun 2013, 13:39:16 Updated by Kevin Lawrence 04 Jun 2013, 07:35:44

It seems that it's not possible to use a route value of '''id''' in a SurfaceController HttpPost, I'm imagining that it conflicts somehow with Umbraco?

As a work-around I renamed my id route value to something else.

Only seems to fail when using the route values overload:

@using (Html.BeginUmbracoForm("Action", "Controller", new ) { }

1 Attachments

Comments

Sebastiaan Janssen 03 Jun 2013, 14:57:16

I can't reproduce this in 6.0.6 and it should never be a problem. Maybe there's an error in the way you're handlin the Id but posting a property with the name Id is not a problem.


Sebastiaan Janssen 03 Jun 2013, 15:00:12

Screenshot (also tried with lowercase id )


Kevin Lawrence 03 Jun 2013, 15:01:04

Hi Sebastiaan

Did you declare your (id) route through BeginUmbracoForm?

i.e.

@using (Html.BeginUmbracoForm("Action", "Controller", new ) { }


Sebastiaan Janssen 03 Jun 2013, 15:12:30

Okay, I think you're going about this in the wrong way.

I have a StatusUpdateSurfaceController with the following Action:

[ChildActionOnly] public ActionResult RenderStatusUpdate() { return PartialView("StatusUpdate", new StatusUpdateModel ); }

Note that the Id is being set here.

I render this using: @Html.Action("RenderStatusUpdate", "StatusUpdateSurface")

Of course this shouldn't be a hardcoded Id but you can put that in a field so that you can fill it from your HttpPost action as well.


Kevin Lawrence 03 Jun 2013, 15:18:39

I don't think I'm going about it the wrong way because if I change Id to something else then it works, which was my work-around in the end.


Kevin Lawrence 03 Jun 2013, 15:24:29

Also, you won't always have a model in some instances, but I hear what you're saying, what I'm doing is probably an edge-case.


Sebastiaan Janssen 03 Jun 2013, 15:31:51

Maybe, I've assigned this to Shannon for some feedback, I'm no MVC expert.


Asbjørn Riis-Knudsen 03 Jun 2013, 15:57:50

Wouldn't you normally use a hidden input to hold the id instead? Not that I'm an expert either...


Kevin Lawrence 03 Jun 2013, 17:12:17

You can use a hidden field, but you should also be able to use the routing as well. In my example I have a button for adding a product to a basket, so I just have a form with a button and it's just cleaner to have the id in the route.


Shannon Deminick 03 Jun 2013, 23:43:52

There's actually a very good reason why you'd want to use parameters instead of hidden fields but I haven't added that to the docs yet :) Its if you want to send a secure/encrypted value in your form instead of a plain text value. It works by setting route parameters because these parameters all get encrypted into the umbraco hidden field.

In any case, I'll try to replicate and see what is going on.


Shannon Deminick 04 Jun 2013, 00:43:25

I also cannot replicate this issue. You say "It seems that it's not possible to use a route value of id in a SurfaceController " ... can you please tell us why this doesn't seem possible ? YSOD? Error, etc.. ?


Shannon Deminick 04 Jun 2013, 00:56:35

Ah figured it out, easy fix in revision 4efd990d88ff


Kevin Lawrence 04 Jun 2013, 07:35:44

Thanks very much Shannon :-)


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.1

Due in version:

Sprint:

Story Points:

Cycle: