我在mvc中工作我有一个窗体使用ajax post,knockout,javascript发布到服务器的视图,名称字段是必需的,并且需要代码字段。形式。因此我用下面的代码名字在我的形式: -html5的验证器(例如不起作用
以下使用JavaScript由我来发布形式
var EmpViewModel = function() {
//Make the self as 'this' reference
var self = this;
//Declare observable which will be bind with UI
self.Code = ko.observable("");
self.Name = ko.observable("");
self.DateOfBirth = ko.observable("");
self.Age = ko.observable("");
self.ContactNumber = ko.observable("");
self.Email = ko.observable("");
self.Address = ko.observable("") ;
self.MaritalStatus = ko.observable("");
self.City = ko.observable("");
self.Reference = ko.observable("");
//The Object which stored data entered in the observables
var EmpData = {
EmpCode: self.Code,
EmpName: self.Name,
Dob: self.DateOfBirth,
Age: self.Age,
ContactNumber: self.ContactNumber,
MaritalStatus: self.MaritalStatus,
EmailID: self.Email,
Address: self.Address,
City: self.City,
Reference: self.Reference
};
//Declare an ObservableArray for Storing the JSON Response
self.Employees = ko.observableArray([]);
//Function to perform POST (insert Employee) operation
this.save = function() {
//Ajax call to Insert the Employee
$.ajax({
type: "POST",
url: "/Exercise/Save/",
data: ko.toJSON(this), //Convert the Observable Data into JSON
contentType: "application/json",
success: function (data) {
alert(data);
window.close();
// opener.location.reload(true);
},
error: function() {
alert("Failed");
}
});
//Ends Here
};
}
ko.applyBindings(new EmpViewModel());
有各种验证存在于我的表格但没有任何作品。表格即使没有填写字段提交?
任何想法来解决这个问题?
+2
你使用什么浏览器?也许它不支持HTML5或此功能。无论如何,你仍然可以自己验证字段,有很多插件和技术。但最后你还需要验证服务器端的数据。 –
2013-03-14 09:27:51
+0
我检查了IE7,Chrome 10和mozila以及.. –
2013-03-14 10:54:00
+1
IE7不支持这种验证,我不确定Chrome 10是什么,但是这听起来也相当古老。当前版本为25. –
2013-03-14 13:39:15