vote up 1 vote down
star
2

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.

flag
add comment

1 Answer:

vote up 0 vote down
check

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.

link|flag
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. – Eric Brown Dec 22 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 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. – Eric Brown Dec 23 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 at 16:26
add comment

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.