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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:23:35+00:00 2026-06-18T16:23:35+00:00

In my controller, I filter a list based on parameters that the user first

  • 0

In my controller, I filter a list based on parameters that the user first choose. It’s like a search engine.

There is a possibility that the list may return 0 values. While this is not an error, I would like to display some kind of message, like an error message, but all I’ve found so far is using the ModelState or ModelStateDictionary in c# which also requires an exception. But this is no exception, just a condition, so I’m a bit puzzled.

I will write out a bit of code so that you will visually see what I want:

    if(listOBJS.count == 0)
    {
        // DISPLAY THE ERROR!
        PopulateDDL1();
        PopulateDDL2();
        return View(listOBJS);
    }

Right, that about what I want to do. How could I proceed? Thanks for the advices.

  • 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-18T16:23:37+00:00Added an answer on June 18, 2026 at 4:23 pm

    ModelState doesn’t require an exception.
    You can just add a Modelstate error with whatever message you want and use the normal method for checking the ModelState.isValid to decide whether to proceed, or return to the view to show the error.

    ModelState.AddModelError("", "Your Error Message");
    

    Alternatively, you could use ViewBag or ViewData to hole the message, as well.

    ViewBag.ErrorMessage = "Your Error Message";
    ViewData["ErrorMessage"] = "Your Error Message";
    

    Then in the view they can be displayed

    @Html.ValidationMessage("ModelName")
    @ViewData["ErrorMessage"]
    @ViewBag.ErrorMessage
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def filters = { forUser(controller:'user', action:'*') { before = { user=springSecurityService.getCurrentUser() log.info(came to filter
I have a drop down list that is used to filter data from a
I'm trying to filter a list of Client entities based on properties of an
The dilemma I'm using a before_filter in my controller that restricts access to admins.
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
I have a tableview with a search display controller. It has been working fine
I have a table view controller that implements UISearchBarDelegate and UISearchDisplayDelegate. I have a
I would like this before filter to run every time the page is loaded
I've got a MVC 3 view which displays a list of items that can
I have product list and I should to filter products by multiple criterias. In

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.