【发布时间】:2012-03-27 14:36:27
【问题描述】:
我有一个带有几个复选框的视图,可以选中或取消选中。我希望始终在复选框中注册任何更改,而不使用提交按钮(用户可能会忘记这样做,这会浪费时间)。
那么,有没有办法在视图中处理这个问题?到目前为止,我只使用控制器来完成这项工作。
那么,一段代码:
@ModelType MvcApplication.OpportuniteDetails
@Code
ViewData("Title")="Details"
@End Code
<script type="text/javascript">
$(function () {
$(':checkbox').change(function() {
$.ajax({
url: '@Url.Action("update")',
type: 'POST',
data: { isChecked: $(this).is(':checked') },
success: function (result) { }
});
});
});
</script>
[... Some code here...]
@Html.Raw("Mail sent?") @Html.CheckBox(Model.Opportunite.Mail)
<input type="checkbox" name="mail" id="mail" onclick="test()" />
【问题讨论】:
标签: javascript vb.net asp.net-mvc-3 razor