我希望在选中复选框时获取复选框的值。我从这个复选框的数据库中获得varchar
值。
如果选中A1
,则varchar
值应为1
,如果选中A2
,则varchar
值应为2
。
请建议我如何获得这些价值观?
模型
public string IsA1 { get; set; }
public string IsA2 { get; set; }
public string IsA3 { get; set; }
public bool A1Value
{
get { return IsA1 == "1"; }
set { IsA1 = value ? "1" : "0"; }
}
public bool A2Value
{
get { return IsA2 == "1"; }
set { IsA2 = value ? "1" : "0"; }
}
public bool A3Value
{
get { return IsA3 == "1"; }
set { A3 = value ? "1" : "0"; }
}
查看
@Html.LabelFor(m => m.IsA1, "A1")
@Html.CheckBoxFor(m => m.A1Value,new { @class = "chk"})
@Html.LabelFor(m => m.IsA2, "A2")
@Html.CheckBoxFor(m => m.A2Value, new { @class = "chk"})
@Html.LabelFor(m => m.IsA3, "A3")
@Html.CheckBoxFor(m => m.A3Value, new { @class = "chk"})
控制器
public ActionResult ABC()
{
Details details = new Details();
var model = new ClsS();
model.IsA1 = "1";
model.IsA2 = "2";
model.IsA3 = "3";
model.spartial = details.spartialSQL(model.IsA1, model.IsA2, model.IsA3);
return View(model);
}
脚本
$('.chk').prop('checked', true);
$('.chk').on('change',function () {
if ($(this).is(':checked')) {
/////
}
});