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

  • Home
  • SEARCH
  • 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 1014043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:42+00:00 2026-05-16T10:11:42+00:00

I have page with a simple table and advanced search form. I pass List<Customers>

  • 0

I have page with a simple table and advanced search form. I pass List<Customers> to the model:

View(List<Customers>);

So what is best way to pass and return data to the search form? I want to use validation or something but I think passing data through ViewData is not good idea. Any suggestions?

  • 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-16T10:11:43+00:00Added an answer on May 16, 2026 at 10:11 am

    You should wrap all your data that is required by you view in a model specific to that view. The advantage to this is you could also include your search criteria in the model which would be empty at first but when your search posted, the model would automatically contain your search criteria so you could reload it when passing back the results. This will help maintain your state between post’s as well.

    This also allows all your view’s data to be type safe where ViewData would not be.

    Eg:

    public class CustomerSearchViewModel
    {
        public List<Customer> Customers { get; set; }
    
        // your search criteria if you want to include it
        public string SearchFirstName { get; set; }
        public string SearchLastName { get; set; }
        public int SearchCustomerID { get; set; }
        // etc...
    }
    

    When you return back the List<Customer> the search criteria would already be filled in your model from the post so your view can default the search criteria back to the corresponding controls (assuming your search results and search inputs controls are on the same view).

    For example, in your post you would accept a CustomerSearchViewModel. Then all you need to do is get your list of customers and add it back to the model and return the same model.

    // assuming you have accepted a CustomerSearchViewModel named model
    model.Customers = GetCustomersForSearchCriteria(model.SearchFirstName,
        model.SearchLastName, model.SearchCustomerID);
    return View(model);
    

    You could also add the validation attributes to your model properties to leverage the built in validation in MVC. This would not be possible if you were using ViewData to pass this data around.

    You have to also consider the ‘next guy’. It’s cleaner when all the data that the view requires is located in a single class. This way they don’t have to hunt through the code to discover if ViewData is being used and what data is actually being passed around in it.

    ViewData is still an option for passing data but I try to minimize the use of it if at all possible.

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

Sidebar

Related Questions

I have a simple form on a view page, implemented as a user control,
I have a simple accordion type page containing a list of H3 headers and
I have an asp.net web page with a simple search text box that returns
I have a very simple table that contains a list of 'victims' and the
I have a simple page with a table and i want it to be
If I have a simple table on a MediaWiki page like this: {|{{#vardefine:new|style=background: none
I have a simple page with my ScriptManager and my UpdatePanel , and my
K... I'm doing something obviously wrong. I have a simple page with a file
I have a simple web page that till now didn't need any login. It
I have a simple cart page that displays items that are in someones cart,

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.