我如何创建此ActionLink的正确路径值? [英] How do I create the correct route values for this ActionLink?

查看:188
本文介绍了我如何创建此ActionLink的正确路径值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SearchResults.aspx 的模型的实例 PersonSearch ;当一个新的页面请求到达(GET请求),操作方法应该把它和计算新的结果。

The Model of SearchResults.aspx is an instance of PersonSearch; when the request for a new page arrive (a GET request), the action method should take it and compute the new results.

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult SearchResults(PersonSearch search, int? page)
{
    ViewData["Results"] = new PaginatedList<Person>(_searchService.FindPersons(search), page ?? 0, 1);
    return View("SearchResults", search);
}

然后我不得不产生previous /下一个链接:

Then I have to generate the previous/next links:

<%= Html.ActionLink("Next Page >", "SearchResults", routeValues) %>

如果我用 routeValues​​ = ViewData.Model 我可以看到对象属性传递的地址,但我不能添加页参数。

If I use routeValues = ViewData.Model I can see the object properties passed the address, but I can't add the "page" parameter.

推荐答案

据认为这将是更好地创造,而不是使用(并有可能改变目前的routevalues​​)用正确的价值观另一个对象:

It think it would be better to create another object with the correct values, instead of using (and potentially altering the current routevalues):

<%=Html.ActionLink("Next Page >", "SearchResults", new {
    search = this.Model,
    page = 1 //or whatever
}) %>

这篇关于我如何创建此ActionLink的正确路径值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆