views:

78

answers:

1

Hi folks,

I've got a simple html form with a few input boxes. When i click save, it finds the correct method but the data is weird. When i have a form field name that is the same name as a field in the route, the value passed in is my form field data, not the route data.

for example.

Imagine u have the following route.

// Both Get/Post
routes.MapRoute(
    "User-Edit",
    "user/{displayName}/edit",
    new { controller = "Account", action = "edit" });

and the following method...

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit([Bind(Exclude = "UserId")]string displayName, 
                               FormCollection formValues)

{ ... }

Now, notice how the route has the variable displayName and the controller action also has a argument called displayName? Well, the argument data is that from the form, NOT the route.

I'm not sure how i can make sure the argument data is the route data?

Is the only fix here for me to rename the route variable, from displayName to routeDisplayName or whatever.. ?

+1  A: 

The ModelBinding conventions stipulate that a parameter is populated from:

  • a request.form value if it exists (yours does!)
  • then, RouteData.Values
  • then request.querystring
  • then null

You would have to (a) override this default behavior or (b) rename your route value.

I would go with b.

Mike

mikerennick
El wikid :) cheers mate.
Pure.Krome