lundi 10 janvier 2022

I am getting null value in the server side from CheckBox in asp.net MVC

When I check the box, it shows it has a false value in the server side model but in the ajax call getting values it shows null values.

In the model class:

[Display(Name = "Is Buyer")]
public bool IsBuyer { get; set; }

In the Razor Page:

<div class="row g-my-4">
    <div class="col-md-10 g-pl-0">
        <div class="row">
            <div class="col-md-1">&nbsp;</div>
            <div class="col-md-7 g-pl-0 g-pr-0" id="IsBuyer">
                <label>
                @Html.CheckBoxFor(m=>m.IsBuyer)
                @*@Html.CheckBoxFor(model => model.IsBuyer, new { id = "CheckBuyer" })*@

                @*@Html.CheckBox("IsBuyer")*@
                Buyer
                </label>
            </div>
        </div>
    </div>
</div>

I tried to use everything but nothing is working.

Getting data values to use ajax call

Getting data values by js

Here you can see the IsBuyer attribute is null = empty, and here on the server side it's getting false value however I have checked every check box but that's what I am getting back

Server side result




Aucun commentaire:

Enregistrer un commentaire