带有回发的最佳使用Razor复选框是什么?例如,我有一门课如下
public class Person
{
public string Name { get; set; }
public string SurName { get; set; }
public bool hi { get; set; }
}
和一个视图(带脚本):
<script type="text/javascript">
$(function () {
$('#hi').change(function () {
$(this).closest("form").submit();
});
});
</script>
@using (Html.BeginForm(FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Person</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SurName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SurName)
@Html.ValidationMessageFor(model => model.SurName)
</div>
@Html.CheckBoxFor(model => model.hi)
</fieldset>
}
当我单击“hi”复选框时,我想要回发。我该怎么做?