1

Is there a way to link to another View that displays search results without having to use a querystring? For example, I know that I can do the following:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string txtOrderNumber)
{
    return RedirectToAction("OrderLookup", new { controller = "Report", id = txtOrderNumber });            
}

But, let's say that I only want to use a hyperlink (a hyperlink with the Order Number) and not a form post. How can I route to the result View without using a querystring? many thanks.

Papa Burgundy
  • 6,197
  • 6
  • 37
  • 48

2 Answers2

3

Rename the txtOrderNumber argument to id. Then it will get picked up by the default route. Alternately, introduce a new route with a value called txtOrderNumber in the same place as the id value in the default route, and constrain it to respond to only this controller.

Craig Stuntz
  • 123,797
  • 12
  • 247
  • 268
  • Thanks Craig. But wouldn't that still show up in the route? Basically I dont want the order number to show up anywhere in the URL. – Papa Burgundy Dec 22 '08 at 21:32
  • If you don't want the search string to come from the URL, a query string parameter, or a form field, where, exactly, do you expect to get it from? – Craig Stuntz Dec 22 '08 at 21:44
  • I guess that was the question. For instance, with WebForms you could use CommandArguement, etc. I just wanted to make sure I wasnt missing something. Im converting a WebForm app that used linkbuttons and didnt show the values in the URL. But it sounds like that may not be possible with MVC. – Papa Burgundy Dec 23 '08 at 16:17
  • Well, MVC can use the same mechanisms that WebForms uses. WebForms uses a form field here, under the hood. You can do the same if you want (and already have, from the looks of the question). You can POST from a link (instead of a button) with JavaScript. – Craig Stuntz Dec 23 '08 at 16:26
0

Eric,

With webforms the command argument is passed by making a post and the value is stored in a control (i believe is stored in a hidden field or the viewstate which is also a hidden field), but the page does post back.

If you don't want to make a post and don't use a querystring the only solution i can come up with is for you to do a post to the same page, capture the id store it in TempData and then do a RedirectToAction. In the controller simply use the TempData value stored from the previous page.

This still generates a post, but if the user refreshes the page they will not see the "Resend Data" message.

Jonas Stawski
  • 6,422
  • 5
  • 58
  • 104