【发布时间】:2017-05-08 20:29:19
【问题描述】:
以下代码从 Angularjs 控制器向 MVC 控制器发送空对象。在“batarang”$scope 中显示 EmployeeInfo 对象,并用适当的值填写 HTML 表单。但是 MVC 方法使所有值都为空。我的代码如下
控制器:
Angular.module("myApp", []).controller("EmployeeBasicCtrl", function ($scope, $http) {
$scope.signBox = false;
$scope.SEX = [
{ text: "Non of above", value: "N" },
{ text: "Female", value: "F" },
{ text: "Male", value: "M" },
]
$scope.submitBasicInfo = function () {
$http({
method: 'POST',
url: '/EmployeeInfo/AddEmployee'
}).success(
function (resp) {
$scope.success = resp.success;
$scope.Message = resp.Message;
}
)// success en
} // end of submit form
})// end of controller
HTML:
<form ng-submit="submitBasicInfo()" name="EmployeeBasic" ng-controller="EmployeeBasicCtrl">
<div class="well">
<input type="hidden" name="EmpID" />
<div class="panel panel-heading panel-primary">
<div class="panel-heading"><h3> Personal Information </h3></div>
<label> First Name </label>
<input name="Fname" class="form-control" ng-model="EmployeeInfo.Fname" required />
<small ng-show="EmployeeBasic.Fname.$touched && EmployeeBasicEmployeeBasic.Fname.$invalid">First Name is mandatory</small><br />
..........
MVC 控制器:
[HttpPost]
public JsonResult AddEmployee(EmployeeInfo para)
{
return Json(new {success="success" },JsonRequestBehavior.AllowGet);
}
EmployeeInfo 类:
public class EmployeeInfo
{
public string EmpID { get; set; }
public string Fname { get; set; }
public string Sname { get; set; }
public DateTime DOB { get; set; }
public string Email { get; set; }
public string Mobile { get; set; }
public string Gender { get; set; }
public string UnitNo { get; set; }
public string StreetNo { get; set; }
public string Suburb { get; set; }
public string StateID { get; set; }
public string PostCode { get; set; }
感谢您的帮助
【问题讨论】:
标签: angularjs model-view-controller model null