Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:33:17+00:00 2026-05-26T05:33:17+00:00

I need to create a link that will be based on my search criteria.

  • 0

I need to create a link that will be based on my search criteria. For example:

localhost/Search?page=2&Location.PostCode=XX&Location.Country=UK&IsEnabled=true 

Parameters in this link are the values of properties in my SearchViewModel.

Ideally I’d like to have something on the lines of:

@Html.ActionLink("Search","User", Model.SearchCriteria)

Is this supported by default or do I need to pass properties of my view model into RouteValueDictionary type object and then use that?

My goal is to write a paging helper which would generate page numbers and append the search criteria parameters to the generated links.

E.g.

@Html.GeneratePageLinks(Model.PagingInfo, x => Url.Action("Index"), Model.SearchCriteria)

I’ve combined your solutions with suggestion from PRO ASP.NET MVC 3 book and ended up with the following:

Helper for generating links. Interesting part is pageUrlDelegate parameter which is later used to invoke Url.Action for generating links:

public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfoViewModel pagingInfo, 
                                        Func<int,String> pageUrlDelegate)
{
    StringBuilder result = new StringBuilder();
    for (int i = 1; i <= 5; i++)
    {
        TagBuilder tagBuilder = new TagBuilder("a");                                
        tagBuilder.MergeAttribute("href", pageUrlDelegate(i));
        tagBuilder.InnerHtml = i.ToString();
        result.Append(tagBuilder.ToString());               
    }            

    return MvcHtmlString.Create(result.ToString());
}   

Then in the view model:

@Html.PageLinks(Model.PagingInfo, x => Url.Action("Index","Search", new RouteValueDictionary()
    {
            { "Page", x },
            { "Criteria.Location.PostCode", Model.Criteria.Location.PostCode },   
            { "Criteria.Location.Town", Model.Criteria.Location.Town},
            { "Criteria.Location.County", Model.Criteria.Location.County}
    }))
)

I’m still not happy with property names in Strings, but It’ll have to do for now.

Thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:33:18+00:00Added an answer on May 26, 2026 at 5:33 am

    Ideally I’d like to have something on the lines of:

    @Html.ActionLink("Search","User", Model.SearchCriteria)

    Unfortunately that’s not possible. You will have to pass properties one by one. You could indeed use the overload which takes a RouteValueDictionary:

    @Html.ActionLink(
        "Search",
        "User",
        new RouteValueDictionary(new Dictionary<string, object>
        {
            { "Location.PostCode", Model.SearchCriteria.PostCode },
            { "Location.Country", Model.SearchCriteria.Country },
            { "IsEnabled", Model.IsEnabled },
        })
    )
    

    Of course it’s probably better to write a custom ActionLink helper to do this:

    public static class HtmlExtensions
    {
        public static IHtmlString GeneratePageLink(this HtmlHelper<MyViewModel> htmlHelper, string linkText, string action)
        {
            var model = htmlHelper.ViewData.Model;
            var values = new RouteValueDictionary(new Dictionary<string, object>
            {
                { "Location.PostCode", model.SearchCriteria.PostCode },
                { "Location.Country", model.SearchCriteria.Country },
                { "IsEnabled", model.IsEnabled },
            });
            return htmlHelper.ActionLink(linkText, action, values);
        }
    }
    

    and then:

    @Html.GeneratePageLink("some page link text", "index")
    

    Another possibility is to pass only the id and have the controller action fetch the corresponding model and values from wherever you fetched it initially in the controller action that rendered this view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a symlink/shortcut on the prod servers that will alias: agent_ivr_general_info.CURRENT
I want to create an item (a link) that will have inner shadows on
I need to create an ODBC link from an Access 2003 (Jet) database to
i need to create a chart similar to this: link text Do you have
I need to create next and previous link urls here's a sample <a href=/calendar/2009/10/>previous</a>
Need to create a custom DNS name server using C which will check against
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create an ASP page (classic, not ASP.NET) which runs remote shell
We need to create a flash application, where there would be a menu page.
I'm trying to create a regular expression that will match the third instance of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.