简体   繁体   English

ASP.Net MVC路由URL QueryString

[英]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. 将txtOrderNumber参数重命名为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. 或者,在默认路由的id值的相同位置引入一个名为txtOrderNumber的新路由,并限制它仅响应此控制器。

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. 使用webforms时,通过发布文章来传递命令参数,并将值存储在控件中(我认为它存储在隐藏字段或也是隐藏字段的viewstate中),但是页面的确发布了。

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. 如果您不想发表文章并且不使用查询字符串,那么我能想到的唯一解决方案是让您在同一页上发表文章,捕获id并将其存储在TempData中,然后执行RedirectToAction。 In the controller simply use the TempData value stored from the previous page. 在控制器中,只需使用上一页中存储的TempData值即可。

This still generates a post, but if the user refreshes the page they will not see the "Resend Data" message. 这仍然会产生一个帖子,但是如果用户刷新页面,他们将不会看到“重新发送数据”消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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