简体   繁体   中英

ASP.Net MVC Routing URL QueryString

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM