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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:06:18+00:00 2026-06-07T12:06:18+00:00

I have a view with two drop downlist which is used to search the

  • 0

I have a view with two drop downlist which is used to search the description. The list of results are displayed in another view for now. I wish to generate the results in the same search view. I assume some AJAX or Jquery can be used to sort this out but don’t know how. So, in this case how can the search result be displayed in the same view page?

Moreover, i have some doubt in Search controller. I want at least one drop down list to be selected (Both drop down list shouldn’t be allowed null). How can i validate that part?

View

@using (Html.BeginForm("Search","Work",FormMethod.Get))
{

    <fieldset>
        <legend>Search</legend>
    <div class="editor-label">
            @Html.LabelFor(model => model.JobTypeID, "Job Type")
        </div>
        <div class="editor-field">
            @Html.DropDownList("JobTypeID", "Select Job Type")
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.JobPriorityID, "Job Priority")
        </div>
        <div class="editor-field">
            @Html.DropDownList("JobPriorityID", "Select Job Priority")
        </div>
         <p>
            <input type="submit" value="Search" />
        </p>
        </fieldset>
}

Controller:

 [HttpGet]
        public ActionResult Search(int? jobtypeid, int? jobpriorityid)
        {
            var vJobDescriptions = new List<JobDescription>();

            if (jobtypeid != null && jobpriorityid != null )
            {
                 vJobDescriptions = (from description in db.JobDescriptions
                                        where (description.JobTypeID == jobtypeid && description.JobPriorityID == jobpriorityid)
                                        select description).ToList();
            }
            else if (jobtypeid == null && jobpriorityid != null)
            {
                 vJobDescriptions = (from description in db.JobDescriptions
                                        where (description.JobPriorityID == jobpriorityid)
                                        select description).ToList();

            }
            else if (jobtypeid != null && jobpriorityid == null)
            {
                vJobDescriptions = (from description in db.JobDescriptions
                                    where (description.JobTypeID == jobtypeid)
                                    select description).ToList();
            }
            else
            {
                vJobDescriptions = (from description in db.JobDescriptions
                                    select description).ToList();
            }


            return View(vJobDescriptions);
        }
  • 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-07T12:06:20+00:00Added an answer on June 7, 2026 at 12:06 pm

    One possibility is to use an Ajax.BeginForm instead of a normal form (don’t forget to include jquery.js and jquery.unobtrusive-ajax.js scripts to your page):

    @using (Ajax.BeginForm("Search", "Work", new AjaxOptions { UpdateTargetId = "results" }))
    

    then you could have a placeholder for the results that we specified in the UpdateTargetId:

    <div id="results"></div>
    

    Now all that’s left is to have your Search controller action return a PartialView and pass it the model containing the results of the search:

    public ActionResult Search(int? jobtypeid, int? jobpriorityid)
    {
        var model = ...
        return PartialView("_Result", model);
    }
    

    and of course the corresponding _Result.cshtml partial:

    @model IEnumerable<MyViewModel>
    ...
    

    Moreover, i have some doubt in Search controller. I want at least one
    drop down list to be selected (Both drop down list shouldn’t be
    allowed null). How can i validate that part?

    I would recommend you FluentValidation.NET but if you don’t want to use third party libraries you could write a custom validation attribute that will perform this validation and then decorate one of the 2 view model properties that are bound to your dropdown lists with it.

    Unfortunately if you decide to go the AJAX route, you will have to be able to display validation errors coming from the server in case there was something wrong. So it is the entire form that has to be put inside the partial.

    Another approach that you could use is to simply reload the entire page using a standard form without AJAX. The results will be part of your initial view model as a collection property which will initially be null and after performing the search you will populate it with the results. Then inside the view you will test if the property is not null and if it isn’t include the Partial that will take care of rendering the results:

    @using (Html.BeginForm("Search", "Work", FormMethod.Get))
    {
        ...
    }
    
    <div id="results">
        @if (Model.Results != null)
        {
            @Html.Partial("_Results", Model.Results)
        }
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have two filtering objects. One is a drop down list, which chooses
I have two view controllers in a tabbar which can both edit data. Therefore,
I have a view with two subviews: A UIImageView A small Custom View which
I have a drop down list and some styles applied to it from two
I have two dropdown list which is question and answer. At first the answer
I have custom control with two textboxes and one drop down list. I want
I have a View Feedback page with two drop down lists to filter the
I have two view controller classes in my application delegate. I can change from
I have two view controllers that allow changes to the Address Book. The first
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have

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.