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 533823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:32:54+00:00 2026-05-13T09:32:54+00:00

I have built an ASP.NET MVC app some time ago, and after a few

  • 0

I have built an ASP.NET MVC app some time ago, and after a few maintenance cycles am wondering whether I took the best approach to state management. Everything works, but I get the feeling there is a better way.

The site is based on a search functionality that has quite a few options. A user starts using the site by filling in a number of search options in a form and clicking the ‘search’ button. This button posts to the Search method with all the search options being defined as parameters to the Search methods, eg:

public ActionResult Search(string param1, string param2, string param3, int? param3, long? param4)

Now the results page that shows up has a number of links on it, leading to various detail pages, etc. Since I need the search state to be preserved on the detail page, I find myself creating ActionLinks with lots of parameters all over the place, such as:

<%=Html.ActionLink("LinkText", "MethodName", new {id="idOfDetailPage", param1=Model.param1, param2=Model.param2, param3=Model.param3, param4=Model.param4}, null)%>

Most of the parameter values in each link do not change from the current state of the search, but I need to pass them in order to be able to create other links in the detail page with the current search parameters, such as “back to search results” for instance.

When I need to add a search parameter due to a new feature request, I find myself modifying a lot of links as well as any Controller methods that the links lead to. This is where I feel that I need a better way.

I have thought about using session state for keeping the search parameters, but for some reason thought this was not the best thing to use in ASP MVC and so am curious if there is another, cleaner way to do this.

Note: I have also tried an approach where I use a strongly typed object in the ActionLink but I still need to pass parameters to that object so it doesn’t get much better.

Any ideas are appreciated.

  • 1 1 Answer
  • 2 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-13T09:32:55+00:00Added an answer on May 13, 2026 at 9:32 am

    Using session state for this kind of thing is alway a nuisance as it means these pages can’t be bookmarked and if you want to have more than one tab open it starts getting messy.

    You could create a new SearchParameters class:

    public class SearchParameters
    {
        public string Param1 { get; set; }
        public string Param2 { get; set; }
    }
    

    modify your Action to be

    public ActionResult Search(SearchParameters params)
    

    and then pass this back to the view through the view data.

    your view should then be able to use

    <%=Html.ActionLink("LinkText", "MethodName", Model) %>
    

    If you’re using this all over the place, you might like to create an HtmlHelper Extension:

    public static class SearchExtensions
    {
        public static string SearchLink<TModel>(this HtmlHelper<TModel> helper, string linkText)
            where TModel : SearchModel, class //required by ASP.NET MVC
        {
            return helper.ActionLink(linkText, "MethodName", modelType.ViewData.Model) %>
        }       
    }
    

    and then your search is as simple as:

    <%=Html.SearchLink("LinkText") %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an ASP.NET mvc web application and it seems that some of
I have an ASP.NET MVC 3 app that I have built as a single
I have an asp.net mvc app that is built to run as standard web
I have an action filter in an ASP.NET MVC 3 app that needs some
I have built an ASP.NET MVC 2 website that I am hosting with Rackspace
I have built a MVC website on IIS6. I used the built-in ASP.NET Security
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
We have an ASP.Net MVC solution built in VS2008 and TFS2008. We use TFS
I have an app built in ASP.NET/C# . I have created a WebSetUp for
So we're having some issues deploying an ASP.NET MVC app to a client site.

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.