Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all
I am passing multiple parameter values from a controller to view through json and
all textbox and DDL values binding except Checkbox values.
tell me the mistake where i missed

What I have tried:

Controller :-
------------
public ActionResult GetAdministratorDetails(string AdministratorID,AdministratorsModel Model, string Command)
        {
            try
            {

             ModelState.Clear();
            AdminControllerPageObject.GetAdministratorDetails(AdministratorID,Model);
            AdminControllerPageObject.GetAdministratorBankDetails(AdministratorID, Model);
            List<AdministratorInformation> AdministratorNameList = AdminControllerPageObject.GetAdministratornamesInfo();
            SelectList Names = new SelectList(AdministratorNameList, "IdRef", "Name");
            Model.AdministratorNameDetails = Names;
            var result = new {IdRef=Model.IDreference,Name=Model.Name, MealEntertainmentCard=Model.MealEntertainmentCard, LivingExpensesCard=Model.LivingExpensesCard};
            return Json(result, JsonRequestBehavior.AllowGet);
           }
            catch (Exception ex)
            {
             logger.Debug(ex.Message.ToString());
             return Json("");
          }
      }


In ViewPage :-
------------
$(document).ready(function () {
        $('#AdministratorName').change(function () {
                   $.ajax({
                            type: "POST",
                            url: '@Url.Action("GetAdministratorDetails", "Admin")',
                            data: { AdministratorID: $('#AdministratorName').val() },
                            datatype: "json",
                            traditional: true,

                            success: function (data) {
                                
                                $(MealEntertainmentCard).val(data.MealEntertainmentCard)                                $(LivingExpensesCard).val(data.LivingExpensesCard);
                                
                            }
                            });
                    });
    });



<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    @Html.CheckBoxFor(m => m.MealEntertainmentCard, new { @class = "input-text chkb"})
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <input type="text" id="meal-entertainment-card" class="form-control col-md-7 col-xs-12" readonly value="Meal Entertainment Card">
        @Html.ValidationMessageFor(m => m.MealEntertainmentCard, "", new { @class = "text-danger" })
    </div>
</div>

<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    @Html.CheckBoxFor(m => m.LivingExpensesCard, new { @class = "input-text chkb" })
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <input type="text" id="living-expense-card" class="form-control col-md-7 col-xs-12" readonly value="Living Expense Card">
        @Html.ValidationMessageFor(m => m.LivingExpensesCard, "", new { @class = "text-danger" })
    </div>
</div>
Posted
Updated 19-Apr-17 20:16pm
v3

1 solution

I don't know how the booleans are represented within your JSON data - ensure that they are convertible to boolean (e.g.: 0 for false and 1 or -1 for true). Then use something like:
HTML
<div class="checkbox">
     @Html.EditorFor(model => model.IsActive)
</div>

Where the presentation of the checkbox depends on the CSS class you're using - this example works with Bootstrap.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900