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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:54:41+00:00 2026-06-05T22:54:41+00:00

I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id

  • 0

I have the following form:

@model Teesa.Models.SearchModel
@using (Html.BeginForm("Index", "Search", FormMethod.Get, new { id = "SearchForm" }))
{
    <div class="top-menu-search-buttons-div">
        @if (!MvcHtmlString.IsNullOrEmpty(Html.ValidationMessageFor(m => m.SearchText)))
        {
            <style type="text/css">
                .top-menu-search-text
                {
                    border: solid 1px red;
                }
            </style>
        }
        @Html.TextBoxFor(q => q.SearchText, new { @class = "top-menu-search-text", id = "SearchText", name = "SearchText" })
        @Html.HiddenFor(q=>q.Page)
        <input type="submit" value="search" class="top-menu-search-submit-button" />
    </div>
    <div id="top-menu-search-info" class="top-menu-search-info-div">
        Please Select one :
        <hr style="background-color: #ccc; height: 1px;" />
        <div class="top-menu-search-info-checkbox-div">
            @Html.CheckBoxFor(q => q.SearchInBooks, new { id = "SearchInBooks", name = "SearchInBooks" })
            <label for="SearchInBooks">Books</label>
        </div>
        <div class="top-menu-search-info-checkbox-div">
            @Html.CheckBoxFor(q => q.SearchInAuthors, new { id = "SearchInAuthors" })
            <label for="SearchInAuthors">Authors</label>
        </div>
        <div class="top-menu-search-info-checkbox-div">
            @Html.CheckBoxFor(q => q.SearchInTags, new { id = "SearchInTags" })
            <label for="SearchInTags">Tags</label>
        </div>
}

and the following Controller and Models :

namespace Teesa.Models
{
    public class SearchModel
    {
        [Required(ErrorMessage = "*")]
        public string SearchText { get; set; }
        public bool SearchInTags { get; set; }
        public bool SearchInAuthors { get; set; }
        public bool SearchInBooks { get; set; }
        public int Page { get; set; }
        public List<SearchBookModel> Result { get; set; }
        public List<SimilarBookModel> LatestBooks { get; set; }
    }

    public class SearchBookModel
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Author { get; set; }
        public string Summary { get; set; }
        public List<Tags> Tags { get; set; }
        public string StatusName { get; set; }
        public string SubjectName { get; set; }
        public string ThumbnailImagePath { get; set; }
        public string BookRate { get; set; }
        public string RegistrationDate { get; set; }
        public int NumberOfVisit { get; set; }
    }
}

[HttpGet]
public ActionResult Index(SearchModel model)
{
    FillSearchModel(model);
    if (ModelState.IsValid)
    {
            string page = model.Page;
        DatabaseInteract databaseInteract = new DatabaseInteract();
        model.Result = new List<SearchBookModel>();
        List<Book> allBooks = databaseInteract.GetAllBooks();
        List<Book> result = new List<Book>();
        #region 
        if (model.SearchInTags)
        {
            var temp = (from item in allBooks
                        from tagItem in item.Tags
                        where tagItem.Name.Contains(model.SearchText)
                        select item).ToList();
            result.AddRange(temp);
        }
        if (model.SearchInBooks)
        {
            var temp = (from item in allBooks
                        where item.عنوان.Contains(model.SearchText)
                        select item).ToList();
            result.AddRange(temp);
        }
        if (model.SearchInAuthors)
        {
            var temp = (from item in allBooks
                        where item.Author.Contains(model.SearchText)
                        select item).ToList();
            result.AddRange(temp);
        }
        #endregion
        #region Paging
        string itemsPerPage = databaseInteract.GetItemsPerPage();
        int ItemInPage = int.Parse(itemsPerPage);
        var pagingParams = Helpers.SetPagerParameters(page, ItemInPage, result);
        ViewBag.AllPagesCount = pagingParams.AllPagesCount;
        ViewBag.CurrentPageNumber = pagingParams.CurrentPageNumber;
        ViewBag.CountOfAllItems = pagingParams.CountOfAllItems.ToMoneyFormat().ToPersianNumber();
        result = pagingParams.ListData as List<Book> ?? result;
        #endregion
        foreach (var item in result)
        {
            var bookRate = (item.BookRate == null || item.BookRate.Count == 0)
                               ? 0.0
                               : item.BookRate.Average(q => q.Rate);
            model.Result.Add(new SearchBookModel
            {
                Author = item.Author,
                Id = item.Id,
                .
                .
                .
            });
        }
    }
    else
    {
        model.Result = new List<SearchBookModel>();
    }
    return View(model);
}

When I submit the form I see the following query strings(Notice the duplicate names) :

http://localhost:2817/Search?SearchText=book&Page=2&SearchInBooks=true&SearchInBooks=false&SearchInAuthors=true&SearchInAuthors=false&SearchInTags=true&SearchInTags=false

But it has to be something like this :

http://localhost:2817/Search?SearchText=book&Page=2&SearchInBooks=true&SearchInAuthors=true&SearchInTags=true

How can I fix it ?
Thanks

  • 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-05T22:54:42+00:00Added an answer on June 5, 2026 at 10:54 pm

    Html.Checkbox (and the related For... methods) generate a hidden input for false, and the checkbox for true. This is to ensure that model binding works consistently when binding.

    If you must get rid of “false” items resulting from the hidden inputs, you’ll need to construct the checkbox inputs yourself (using HTML and not the helper).

    <input type="checkbox" id="SearchInBooks" name="SearchInBooks">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form: <li> <% using (Html.BeginForm(TestMethod, MyController, FormMethod.Post, new {id =
I have following code @using (Html.BeginForm()) { @Html.DropDownListFor(m => m.IDs, new SelectList(Model. IDs), Model.SelectedID)
I have the following form in a partial view @model PartDetail @using (Ajax.BeginForm(Create, Part,
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I have the following code: private Models.mediamanagerEntities dataModel = new Models.mediamanagerEntities(); public ActionResult Index(FormCollection
I have the following code: // Form the continuities list string[] continuities = new
I have the following form: class ModuleItemForm2(forms.ModelForm): class Meta: model = Module_item fields =
I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :

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.