ASP.NET MVC Routing URL QueryString

Is there a way to link to another view that displays search results without having to use a query? For example, I know 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 want to use a hyperlink (hyperlink with an order number) and not a form post. How can I redirect to the View result without using a query? many thanks.

+1


source to share


2 answers


Rename the txtOrderNumber argument to id. Then it will be selected by default. Alternatively, introduce a new route with a txtOrderNumber value in the same place as the id value in the default route, and restrict it to respond to this controller only.



+3


source


Eric,

With webforms, the command argument is passed by creating a message and the value is stored in the control (I believe it is stored in a hidden field, or in the view, which is also a hidden field), but the page posts back.



If you don't want to post and don't use a request, the only solution I can think of is to post the post on the same page, grab the ID, store it in TempData, and then do RedirectToAction. In the controller, just use the TempData value saved in the previous page.

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

0


source







All Articles