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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:31:15+00:00 2026-06-14T19:31:15+00:00

i am using asp.net mvc3 and i am going to implement advance search this

  • 0

i am using asp.net mvc3 and i am going to implement advance search
this is my advance search form

 @using (Html.BeginForm("AdvanceSearch","Coupon",FormMethod.Post))
    {
        @Html.ValidationSummary(true)
        <fieldset>

            <div class="editor-label">
                @Html.LabelFor(model => model.AdvanceSearch.CouponName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.AdvanceSearch.CouponName)
                @Html.ValidationMessageFor(model => model.AdvanceSearch.CouponName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.AdvanceSearch.Category)
            </div>
            <div class="editor-field">
                @Html.DropDownList("categories", new SelectList(Model.AdvanceSearch.Category.OrderBy(c=>c.Name).Select(c => c.Name)), "--- Select Categories ---")
                @Html.ValidationMessageFor(model => model.AdvanceSearch.Category)
            </div>
            <div class="editor-label">

                <div class="editor-label">
                    @Html.LabelFor(model => model.AdvanceSearch.CreateDate)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.AdvanceSearch.CreateDate, new { @class = "picker" })
                    @Html.ValidationMessageFor(model => model.AdvanceSearch.CreateDate)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.AdvanceSearch.ExpiredDate)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.AdvanceSearch.ExpiredDate, new { @class = "picker" })
                    @Html.ValidationMessageFor(model => model.AdvanceSearch.ExpiredDate)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.AdvanceSearch.PublishDate)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.AdvanceSearch.PublishDate, new { @class = "picker" })
                    @Html.ValidationMessageFor(model => model.AdvanceSearch.PublishDate)
                </div>
                @Html.LabelFor(model => model.AdvanceSearch.Company)
            </div>
            <div class="editor-field">
                @Html.DropDownList("companies", new SelectList(Model.AdvanceSearch.Company.OrderBy(c=>c.Name).Select(c => c.Name)), "--- Select Companies ---")
                @Html.ValidationMessageFor(model => model.AdvanceSearch.Company)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.AdvanceSearch.Description)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.AdvanceSearch.Description)
                @Html.ValidationMessageFor(model => model.AdvanceSearch.Description)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.AdvanceSearch.IsPublish)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.AdvanceSearch.IsPublish)
                @Html.ValidationMessageFor(model => model.AdvanceSearch.IsPublish)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.AdvanceSearch.Active)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.AdvanceSearch.Active)
                @Html.ValidationMessageFor(model => model.AdvanceSearch.Active)
            </div>

            <p>
                <input type="submit" value="Search" />
            </p>
        </fieldset>
    }

now the problem is that i have following scenarios

  • if only CouponName is given then all coupons contains specified name will be returned
  • if any company is selected from company list then we will search all coupon from that company having specified name will be returned
  • if any Category is selected from category list then we will search all coupon from that category having specified name will be returned
  • if any date from all of threee date is been selected then we will filter coupon by that date

now i am confused that what is the best way to do that , should i implement if else conditions , switch or what ?

  • 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-14T19:31:17+00:00Added an answer on June 14, 2026 at 7:31 pm

    Not sure if there is a “best way”. It all depends on how you are applying the filter.

    I use LINQ to apply filters and like to write my filter construction with a base expression, and then AND expressions for every provided filter selection. I use some extension methods to make this easier. Then you can build your filter expression in steps, and as it get more complex, you can implement steps accordingly. Each basic step would have a if check to see if a particular part was specified, and if it was append it to the base expression.

    // Example of service for applying filter
    public GetProductsResponse GetProducts(GetProductsRequest request)
    {
        // base expression is true, ie always returns everything
        Expression<Func<ProductEntity, bool>> filterExpression = i => true;
    
        // subsequent filters narrow base expression results
        if (!request.IncludeDeleted)
            filterExpression = filterExpression.And(i => i
                .IsDeleted == false);
    
        // I like to use nullable types so that I can check whether a parameter is specified or not
        if (request.CouponName != null)
            filterExpression = filterExpression.And(i => 
                i.CouponName == request.CouponName.Value);
    
        if (request.Company!= null)
            filterExpression = filterExpression.And(i => 
                i.Company== request.Company.Value);
    
        // etc.
    
        var products = _dataContext.Products.Where(filterExpression);
    
        // you probably want to transform products into some sort of model specific class
    
        return new GetProductsRequest
        {
            products = products;
        };
    }
    
    
    // Extension methods for Linq And and Or helpers
    public static class Utility
    {
        public static Expression<T> Compose<T>(this Expression<T> first, Expression<T> second, Func<Expression, Expression, Expression> merge)
        {
            // build parameter map (from parameters of second to parameters of first)
            var map = first.Parameters.Select((f, i) => new { f, s = second.Parameters[i] }).ToDictionary(p => p.s, p => p.f);
    
            // replace parameters in the second lambda expression with parameters from the first
            var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);
    
            // apply composition of lambda expression bodies to parameters from the first expression 
            return Expression.Lambda<T>(merge(first.Body, secondBody), first.Parameters);
        }
    
        public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
        {
            return first.Compose(second, Expression.And);
        }
    
        public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
        {
            return first.Compose(second, Expression.Or);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Ajax.BeginForm helper in ASP.NET MVC3 to submit a form that replaces
I am going to build my application using asp.net mvc3 and nhibernate 3.2. I
I am using ASP.NET MVC3 for a form that has both server and client
I am using Asp.Net MVC3, for a project. In one of the page, I
I am using ASP.NET MVC3 with EF Code First. I have not worked previously
I'm developing a dashboard using ASP.NET MVC3 and need to have two divs which
I'm developing a web service using ASP.NET MVC3. One of the methods of the
In ASP.NET MVC3, when a view model is passed into a view using return
Possible Duplicate: ASP.NET MVC3 how to excute action method of controller using timer with
Assume that: An ASP.NET MVC3 Page (using visual studio debug server) calls a WCF

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.