//Part of View
<div class="checkbox">
<label id="sendEmail" class="" >
<input id="sendEmailInput" type="checkbox" asp-for="CompanySetting.SendEmail">Send mail for jobs.
</label>
</div>
//Model
public partial class CompanySetting
{
public int CompanyId { get; set; }
public bool SendEmail { get; set; }
public virtual CompanyUsers Company { get; set; }
}
//Controller
public ActionResult AccountSettingSave(CompanyAccountViewModel model)
{
try
{
CompanySetting settingModel = _companySettingService.GetByCompanyId(GetId());
settingModel.SendEmail = model.CompanySetting.SendEmail;
_companySettingService.UpdateBill(settingModel);
TempDataMessage("message", "Hesap ayarları başarıyla güncellendi.");
return RedirectToAction("AccountSettings");
}
catch
{
TempDataMessage("message", "Hesap ayarları güncellenemedi.");
return RedirectToAction("AccountSettings");
}
}
Checbox不影响模型,它始终是默认值。可能复选框只返回。但我尝试使用javascript +额外的一个输入和工作。我不想使用javascirpt控件
答案 0 :(得分:0)
order by s.product, (case when Patindex('% ,.,-%', s.product)=0 then 0
else Cast(SUBSTRING(s.product, Patindex('%[0-9]%', s.product), len(s.product)) as int) end)
此代码有效。我应该使用它吗?
答案 1 :(得分:0)
这是因为当选中/取消选中复选框时,属性值为&#39;没有改变,它正在改变数据 - 值。这就是更改不与模型绑定的原因。
您可以使用解决方法。我在下面使用了更简单的解决方案,它通过javascript将data-val的Property值传递给value。
<input asp-for="@Model.sendMail" type="checkbox" value="@Model.sendMail" /> Approve?
<script>
$('#sendMail').on('change', function () {
$('#sendMail').val($('#sendMail').attr('data-val'));
});
</script>