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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:58:48+00:00 2026-06-15T11:58:48+00:00

I have read many questions and tutorials about this, I couldn’t find a case

  • 0

I have read many questions and tutorials about this, I couldn’t find a case similar to mine.

I have an index view which has a search form inside to filter results available in my database.

Here’s the simplified version my controller action for my index view:

[HttpPost]
    public ActionResult Index(String carMake, String carModel)
    {
        var cars = from d in db.Cars
                    select d;

        if (!String.IsNullOrEmpty(carMake))
        {
            if (!carMake.Equals("All Makes"))
            {
                cars = cars.Where(x => x.Make == carMake);
            }
        }

        if (!String.IsNullOrEmpty(carModel))
        {
            if (!carModel.Equals("All Models"))
            {
                cars = cars.Where(x => x.Model == carModel);
            }
        }

        cars = cars.OrderBy(x => x.Make);
        return View("SearchResult", cars);
    }

as you can see, I get the data from Index view and post it to my SearchResult view directly without the use of any public ActionResult SearchResult(){...}. But I do have public ActionResult SearchResult(){...} method in my controller.

Now, I’m trying to sort my results. How can I do that?

I have tried many different ways to pass data from my Index method to Search Result method such as TempData and so on. But the problem with them is when I click on the sort button the page reloads and the Query that I have taken from my Index view form will be all null because TempData is only useful for passing data among methods and when the method is recalled, the data will be gone and all null.

I have some solutions in my mind but I’m not sure if they will work out and if they’re the best/easiest solution possible to come up with. Which is recording the Query I get from my Index page into a table (I don’t think would be a wise thing to do tho).

  • 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-06-15T11:58:49+00:00Added an answer on June 15, 2026 at 11:58 am

    I think it should be as;

    [HttpPost]
    public ActionResult Index(String carMake, String carModel)
    {
       //Redirect to SearchResults. You can do this from client as well.
       return RedirectToAction("SearchResult",  
                    new { make = carMake, model = carModel });
    }
    
    //Add your filter and order code here
    public ActionResult SearchResult(String make, String model)
    {
         var cars = from d in db.Cars
                    select d;
    
        if (!String.IsNullOrEmpty(make))
        {
            if (!carMake.Equals("All Makes"))
            {
                cars = cars.Where(x => x.Make == make);
            }
        }
    
        if (!String.IsNullOrEmpty(model))
        {
            if (!carModel.Equals("All Models"))
            {
                cars = cars.Where(x => x.Model == model);
            }
        }
    
        cars = cars.OrderBy(x => x.Make);
        return View(cars);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many questions and answers, but I couldn´t find solution for my
Having read many tutorials, articles and questions, I am still have confusions about updating
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read many questions here about using mysql in background using php, and
I have read many questions/answers and tutorials and I still fail to implement hierarchical
I have read many question about improving the performance of C++ and C code
My question is in relation this this answer. https://stackoverflow.com/a/8773953/1297775 I have read at many
I have read many answers regarding this still i am getting confused if i

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.