[英]Select option passing null to database
I have a view as below: 我有如下观点:
<select ng-model="d" ng-options="k.id as k.name for k in act"></select>
<input type="submit" value="Create" ng-click="CreateOpen(Emp)" class="btn btn-default" />
</div>
My Js is as below: 我的Js如下:
app.factory('crudServiceUser', function ($http) {
crudUserObj = {};
crudUserObj.Create = function (openact) {
var Emp;
Emp = $http({
method: 'Post',
url: '/Employee/BankAccount/Index',
data: openact
}
).then(function (response) {
return response.data;
});
return Emp;
}
return crudUserObj;
});
app.controller('usersController', function ($scope, crudServiceUser) {
$scope.CreateOpen = function (openact) {
crudServiceUser.Create(openact).then(function (result) {
$scope.Msg = alert(result.EName + " Has Been Created Successfully");
})
}
Here is my action method: 这是我的操作方法:
public ActionResult Index(tblOpenAct tblopact)
{
if (ModelState.IsValid)
{
objemp.OpenActBs.Insert(tblopact);
return RedirectToAction("Index");
}
return View(tblopact);
}
But the select option is inserting null to database but if I use textbox then it inserts data. 但是select选项将null插入数据库,但是如果我使用文本框,则它将插入数据。
Try like bellow 像波纹管一样尝试
<select ng-model="d" >
<option ng-repeat="k in act" value="{{k.id}}">{{k.name }} </option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.