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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:41:54+00:00 2026-05-30T21:41:54+00:00

Hi, I have a .net class that contains a Boolean, this class is sent

  • 0

Hi,

I have a .net class that contains a Boolean, this class is sent to client with AJAX. The problem is that if I just use :

if(MyClass.CheckedValue)

It will always be true even if the CheckedValue is false. I supose that it is instead checking if the object is set and if so it is true? Im note sure what type this Boolean propertie gets when returning to the javascript after AJAX?

I have also tried this :

var checked;
checked = Boolean(this.CheckedValue === 'true');

if (checked)

But this will also laways be true?

How do I handle this?

Edit1 :

The classes that is sent to client :

/// <summary>
/// Are set to client with Ajax to render a correct view of the
/// current category and filter settings
/// </summary>
public class GetCategoriesAndFiltersAjax
{

    public GetCategoriesAndFiltersAjax()
    {
        Filters = new Filter();
    }

    public SelectList categoryList { get; set; }
    public Filter Filters { get; set; }

    public class Filter
    {
        public Filter()
        {
            DefaultFilters = new List<CategoryItemFilter>();
            FilterList = new List<CategoryItemFilter>();
        }

        /// <summary>
        /// Filters like buy, sell, let and so on
        /// </summary>
        public List<CategoryItemFilter> DefaultFilters { get; set; }
        /// <summary>
        /// All other filters that a category might be bound to
        /// </summary>
        public List<CategoryItemFilter> FilterList { get; set; }
    }
}


public class CategoryItemFilter
{
    private int _filterId = -1;

    private string _clientElementId1;
    private string _clientElementId2;

    public FilterControlType FilterControlType { get; set; }
    public string Title1 { get; set; }
    public string Title2 { get; set; }
    public string ClientElementId1
    {
        get { return _clientElementId1; }
        set
        {
            _clientElementId1 = value;
        }
    }
    public string ClientElementId2
    {
        get { return _clientElementId2; }
        set
        {
            _clientElementId2 = value;
        }
    }
    /// <summary>
    /// Keep track of whitch filter it is
    /// </summary>
    public int FilterId
    {
        get { return _filterId; }
        set { _filterId = value; }
    }

    #region Values
    public Boolean CheckedValue { get; set; }
    public string TextValue { get; set; }

    public SelectList DropDownList1 { get; set; }
    public SelectList DropDownList2 { get; set; }
    #endregion

    public PublicAdFilterKey PublicAdFilterKey { get; set; }
}

And this is how the AJAX method looks like on server :

public JsonResult GetCategoriesByParent(int id, Boolean editMode)
{
    FilterModel filterModel = new FilterModel();
    CategoryModel categoryModel = new CategoryModel();
    List<ModelViewCategory> mvCategoryList = new List<ModelViewCategory>();
    //List<AdCategory> categoryList;
    FilterHandler filterHandler = new FilterHandler();

    GetCategoriesAndFiltersAjax value = new GetCategoriesAndFiltersAjax();
    try
    {

        value.categoryList = new SelectList(categoryModel.GetCategoriesByParent(id).ToArray(), "Id", "Name");

        if (editMode)
            value.Filters = filterHandler.ConvertFilterModelToAjaxCategoryFilter(filterModel.GetCategoryFilterByCategory(id), Biss.Views.ViewClasses.Filter.FilterType.Edit);
        else
            value.Filters = filterHandler.ConvertFilterModelToAjaxCategoryFilter(filterModel.GetCategoryFilterByCategory(id), Biss.Views.ViewClasses.Filter.FilterType.Display);

        return this.Json(value, JsonRequestBehavior.AllowGet);
    }
    catch (Exception ex)
    {
        throw;
    }
}

Edit 2 :

This is how the client looks like(not exacly but close, its alot more complicated)

$.ajax({
                            url: actionPath,
                            type: 'POST',
                            dataType: 'json',
                            data: ((typeof config.postData == "function") ? config.postData() : config.postData) || { id: $(source).val(), editMode: _filterInEditMode },
                            success: function (data) {
                                methods.reset();
                                $.each(data.categoryList, function () {
                                    SetFilterSubEdit(data.DefaultFilters);
                            },
                            error: function () {
                                methods.showError();
                            }
                        });


function SetFilterSubEdit(data) {
    $.each(data, function () {
       if (data.CheckedValue)
                    $("#" + visibleElements[0]).attr('checked', checked);
    }
}
  • 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-30T21:41:56+00:00Added an answer on May 30, 2026 at 9:41 pm

    Sorry, the problem was that the brackets was missing on client side.

    if (data.CheckedValue){
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ASP.NET MVC 2, I have a Linq to sql class that contains a
I have a web solution that contains 5 class libraries and one asp.net web
I have an assembly (.NET class library) that contains an object that implements EAP
I have a .NET class library (as a .dll file) and that library contains
I have a class that contains hierarchical data. I want to present this data
I have a .Net 3.5 class library project that I've migrated to use Visual
If I have a .Net class that is not part of any namespace then
if i have a .net 1.1 class that inherits from DictionaryBase and i am
I have a .NET class library containing a class with a method that performs
I have an ASP.NET VB.NET web project that references a VB.NET class library. I

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.