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.

Print | posted on Friday, November 07, 2008 5:35 PM

Feedback


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 6:09 PM 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.


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 6:19 PM JD Pihl

Yeah that's caught me off guard a few times as well..
Not too sure what the reason for it is.


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 6:51 PM Simone

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


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:11 PM Jeremy D. Miller

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


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:16 PM Dave

Dude, get over it.


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:27 PM 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?


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:27 PM 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.


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:32 PM 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.


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:32 PM Ayende Rahien

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


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:34 PM Tuna Toksöz

IE 7.0


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 7:38 PM Ayende Rahien

Fixed, thanks


Gravatar

# re: Title left blank since I can't think of non inflammatory title for this post 11/7/2008 11:41 PM 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.