Javascript 无法在angularjs中的sql server数据库中添加数据?
我在Angularjs中有一个简单的应用程序,我在Angularjs中几乎没有经验。 我的问题是我可以在数据库中添加数据。我想我没有任何错误阻止我添加这些数据 没有显示错误,但数据发送不正确 政府控制器Javascript 无法在angularjs中的sql server数据库中添加数据?,javascript,c#,jquery,angularjs,model-view-controller,Javascript,C#,Jquery,Angularjs,Model View Controller,我在Angularjs中有一个简单的应用程序,我在Angularjs中几乎没有经验。 我的问题是我可以在数据库中添加数据。我想我没有任何错误阻止我添加这些数据 没有显示错误,但数据发送不正确 政府控制器 public ActionResult Index(Governorate gov) { string message = ""; if (ModelState.IsValid) { using (Docto
public ActionResult Index(Governorate gov)
{
string message = "";
if (ModelState.IsValid)
{
using (DoctorEntities dc = new Models.DoctorEntities())
{
dc.Governorates .Add(gov);
dc.SaveChanges();
message = "تم اضافة المحافظة";
}
}
else
{
message = "خطا";
}
return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
gov.js
(function () {
angular.module('MyApp', [])
.controller('AdminController', function ($scope, RegisterService) {
$scope.submitText = "save";
$scope.submitted = false;
$scope.message = '';
$scope.isFormValid = false;
$scope.gov = {
GovernorateName: ''
};
$scope.$watch('f1.$valid', function (newValue) {
$scope.isFormValid = newValue;
});
$scope.SaveDate = function (data) {
if (submitText == "save") {
$scope.submitted = true;
$scope.message = '';
}
if ($scope.isFormValid==false){
$scope.submitText = "please wait....";
$scope.gov = data;
RegisterService.SaveFoemData($scope.gov).then(function (d) {
alert(d);
if (d == 'success') {clearform(); }$scope.submitText='save';
} );
}
else{
$scope.message='please fill required data';
}
};
function clearform(){
$scope.gov=null;
$scope.f1.$setPristine();
$scope.submitted=false;
}})
.factory('RegisterService', function ($http,$q) {
var fac = {};
fac.SaveFoemData = function (data) {
var defer = $q.defer();
$http({
url: '/Gover/Index',
method: 'get',
data: JSON.stringify(data),
headers: {'content-type':'application/json'}
}).success(function (d) {
defer.resolve(d);
}).error(function (e) {
defer.reject(e);
});
return defer.promise();
}
return fac;
});
})()
AddGov.cshtml
@{
ViewBag.Title = "AddGov";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>AddGov</h2>
<div ng-controller="AdminController">
<form novalidate name="f1" ng-submit="SaveData(gov)">
{{message}}
<table>
<tr>
<td>
<input type="text" ng-model="gov.GovernorateName" name="GovernorateName" ng-class="submitted?'ng-dirty':''" required autofocus />
</td>
</tr>
<tr>
<td><input type="submit" value="{{submitText}}" /></td>
</tr>
</table>
</form>
</div>
@section scripts{
<script src="~/Scripts/MyProject/gov.js"></script>
}
@{
ViewBag.Title=“AddGov”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
阿德戈夫
{{message}}
@节脚本{
}
我试图找到这个问题的答案