[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

MVC tempdata issue - appending query string ID to URL

I have an MVC2 app which has a user control comprising of a dropdown (html.dropdownfor).  Its in the master page of the app.

If you click the dropdown it does a GET to select a customer details view

        <% using (Html.BeginForm("CustDetails", "Cust", FormMethod.Get))
           { %>
        <%= Html.DropDownList("id", Model.CustList)%>

If you select a customer from the dropdown and click go the customer details form is submitted.

This works fine as the query string is     /Cust/CustDetails?id=18

And it populated the customer details view.  

Now if I edit the customer details view this also works fine as the URL is this

/Cust/Edit/19

However if I now click on the dropdown user control above and click go the URL is now like this

/Cust/CustDetails/19?Id=18

This only happens when I pass TempData to the view like this from the edit controller.

TempData["CustomerLevel"] = "Your level has been accepted.";

Is there anything with TempData I need to be aware of?
0
ToString1
Asked:
ToString1
  • 2
1 Solution
 
BardobraveCommented:
I think your problem here is that the previous ID data (19 in your example) is being passed to the controller when you make the GET, so your querystring is screwed and your controller is lost.

0
 
ToString1Author Commented:
OK thanks. How can I fix it
0
 
BardobraveCommented:
I think your problem could be related to the positioning and building of the html forms inside your page.

You must check the html code of the pages to see why the parameter 19 is being sent when you make the get. If the two forms are clearly separated this shouldn't be happening, so probably there's some type of mess there.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now