将部门提交到服务器保存后,如何清除视图模型中部门名称的值?这是我的代码:
self.AddDepartmentModel.AddDepartment = function () {
self.errors = ko.validation.group(this, { deep: true, observable: false });
if (self.AddDepartmentModel.errors().length == 0) {
$.ajax({
url: "/Department/Add/",
type: 'post',
data: ko.toJSON(self.AddDepartmentModel),
contentType: 'application/json',
success: function (result) {
$('#success').html('Department Added Successfully.');
$("#success").dialog({
dialogClass: 'noclose',
autoOpen: true,
show: "blind",
hide: "explode",
modal: true,
open: function(event, ui) {
setTimeout(function() {
$('#success').dialog('close');
}, 3000);
}
});
self.ListOfDepartments.GetListOfAllDepartments();
$("#departmentNameTextbox").val("");
self.AddDepartmentModel.DepartmentName = null;
}
});
} else {
self.AddDepartmentModel.errors.showAllMessages();
return;
}
};
我希望在按下提交按钮后清除该字段。如果我只是将字段值设为空字符串并再次点击提交,它会在我清除它后提交文本框中的值。有什么建议如何清除 DepartmentName 的值?
谢谢