Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
@Html.CheckBoxFor(model => model.IsPrint, new { id = "sendCorrMail" }) @Html.LabelFor(m => m.IsPrint)


this is how I am checking the check box but the model.Isprint is not being passed as true when I auto select?

$('#sendCorrMail').attr('checked', 'checked');
Posted

Try like below

Put the below markup like below
@model SampleModel
@using (Html.BeginForm("PostCheckBox", "Sample", FormMethod.Post))
{
    @Html.CheckBoxFor(model => model.IsChecked, new { id = "sendCorrMail" })
    <input type="submit" value="Click"/>
}


Create a Model class
C#
namespace MVCFileUpload.Models
{
    public class SampleModel
    {
        public bool IsChecked { get; set; }
    }
}

Create an ActionResult
SQL
[HttpPost]
      public ActionResult PostCheckBox(SampleModel sampleModel)
      {
          return View("Index");
      }


Hope this helps
 
Share this answer
 
v2
I was to resolve the issue with the help of Jquery... this is what I did to resolve the issue..


this is the hidden field I added...

@Html.HiddenFor(model => model.IsMailMandatory, new { @class = "hiddenIsMailMandatory" })

this is the jquery...

PHP
//to auto select the Mail if the mail is the only delivery option.
if ($('.hiddenIsMailMandatory').val() == 'True') {
    var $sendCorrMail = $('#sendCorrMail');
    var $hdnInput = $sendCorrMail.siblings('input[type="hidden"][name="' + $sendCorrMail.attr('name') + '"]');
    $sendCorrMail.prop('checked', true).attr('disabled', 'disabled');
    $hdnInput.val('true');
 
Share this answer
 
v2

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