Ayende @ Rahien

Unnatural acts on source code

Title left blank since I can't think of non inflammatory title for this post

This works:

image

This doesn't:

image

I haven't bothered to find why, but that is surprising to me. (Note that here the enctype is specified as "multipart/form-data", which may or may not be related)

Update: It is not related.

The real culprit, as best I was able to reconstruct is because of this piece of code:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", 
        "{controller}/{action}/{id}", 
        new {controller = "Home", action = "Index", id = String.Empty} 
        );
}

It looks fairly innocuous, doesn't it?

Except that this means that when ASP.Net MVC looks for a matching value for the "id" parameter, it will only look in the route parameters, and not look at the request parameters.

I found this surprising, to say the least.

Comments

Haacked
11/07/2008 04:09 PM by
Haacked

Without more details, it's hard to tell what's going on. We do look in the Request first before we look at route data to populate action method parameters so what you found is surprising to me as well.

JD Pihl
11/07/2008 04:19 PM by
JD Pihl

Yeah that's caught me off guard a few times as well..

Not too sure what the reason for it is.

Simone
11/07/2008 04:51 PM by
Simone

Maybe it's because the default "id" that comes from the route overrides the "id" that is supplied by the Request

Jeremy D. Miller
11/07/2008 05:11 PM by
Jeremy D. Miller

We got around that little issue by using a "CompositeDictionary" that wraps HttpRequest and the routing dictionary.

Dave
11/07/2008 05:16 PM by
Dave

Dude, get over it.

Simone
11/07/2008 05:27 PM by
Simone

On a side note, the title of this post is "inflammatory":

"Title left blank since I can't think of non inflammatory title for this post"

Don't you ever make mistakes?

Why don't you just do as everyone else and post questions on the ASP.NET forum or stackoverflow?

It could be a bug , why should you start a flame (as the title implies) over a bug?

Tuna Toksöz
11/07/2008 05:27 PM by
Tuna Toksöz

Ayende I think one of the quotes in the code is not recognized, thus the rest of the page has brown font color.

Ayende Rahien
11/07/2008 05:32 PM by
Ayende Rahien

Simone,

This is a reaction to people calling my previous post title inflammatory.

Since I couldn't think of any title that couldn't be constructed as inflammatory, I used that one.

And I am not generally strong on forums, I generally have a strong dislike of them.

I am doing what I always did, putting stuff that I run into during my work on the blog.

Ayende Rahien
11/07/2008 05:32 PM by
Ayende Rahien

I am not seeing that, what browser are you using?

Joe
11/07/2008 09:41 PM by
Joe

@Phil,

Actually I've run into the same issue today and IIRC in previous releases you used to do this but recently it seems to have changed. In fact, if you have a route parameter and a POST field with the same name, then the same issue occurs. Can you confirm this to be a bug or intentional change?

Comments have been closed on this topic.