views:

572

answers:

2

Say I have a route like this:

"{controller}/{action}/{roomId}/{name}"

And a form action like this (And yes it looks like this in the action in the html ie post server processing):

Room/Index/6/SomeThing?pageNumber=1&amountToShow=5

And the form is simple:

<form action = "Room/Index/6/SomeThing?pageNumber=1&amountToShow=5" method="get">
   <button type="submit">SomeButton</button>
</form>

Now when the button is clicked, the request somehow seems to half lose the pageNumber=1&amountToShow=5 part. In fact, when I looked in the ActionExecutingContext.ActionParameters list, the parameters are there (pageNumber and amountToShow) but there are no values. I even looked in the request, and there are no request parameters despite it knowing the url is "Room/Index/6/SomeThing?pageNumber=1&amountToShow=5".

I thought that maybe this had to do with the button and form, and maybe this wasn't possible but then I adjusted the route to:

"{controller}/{action}/{roomId}/{name}/{pageNumber}/{amountToShow}"

And it works, except the url is super formatted:

 Room/Index/6/SomeThing/1/5

Which is to be expected since it's apparently doing it's job this time. Any ideas?

UPDATE

As suggest below by Adrian Godong, I tried using hidden inputs and it works but this still raises more questions. Why is it that with the more verbose route was able to handle the request parameters without hidden values but the shortened route isn't.

+1  A: 

Have you tried moving the query string parameters into hidden input fields?

So, instead of your form block, try this:

<form action = "Room/Index/6/SomeThing" method="get">
    <input type="hidden" name="pageNumber" value="1" />
    <input type="hidden" name="amountToShow" value = "5" />
    <button type="submit">SomeButton</button>
</form>
Adrian Godong
I can give that a try but still wondering why the action fails like this.
Programmin Tool
This works but only adds to the confusion. There has to be something odd going on with forms, get, and routes.
Programmin Tool
A: 

I think it gets munged cause when you submit a form via get it appends ‘?formvalue=value&otherfield=annothervalue...’ to the request string. This may cause your ‘?stuff=value’ to get ignored by IIS/ASP.

DrydenMaker