邮政编号数据类型
时的Angular问题1 - 这是我的模特
public class TaxSliced
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string Name { get; set; }
public int From { get; set; }
public int To { get; set; }
}
2-这是web api
public class TaxesSlicedController : ApiController
{
TaxesSlicedBLL taxesSlicedBLL;
// GET api/taxsliced
public IEnumerable<TaxSliced> Get()
{
using (taxesSlicedBLL = new TaxesSlicedBLL())
{
return taxesSlicedBLL.GetAll(null);
}
}
// POST api/taxsliced
public void Post(TaxSliced entity)
{
if (ModelState.IsValid && entity != null)
{
taxesSlicedBLL = new TaxesSlicedBLL();
taxesSlicedBLL.Add(entity);
}
}
}
3-this html page
<form name="form" role="form" novalidate>
<label>{{translation.NameAR}}</label><br />
<input type="text" ng-model="TaxSliced.NameAR">
<br />
<label>{{translation.NameEN}}</label><br />
<input type="text" ng-model="TaxSliced.NameEN">
<br />
<label>{{translation.From}}</label><br />
<input type="number" ng-model="TaxSliced.From" required>
<br />
<label>{{translation.To}}</label><br />
<input type="number" ng-model="TaxSliced.To" min="0" max="9999" required>
<br />
<button type="submit" ng-click="addTax()" >{{translation.Add}}</button>
<button ng-click="cancelAddTax()">{{translation.Cancel}}</button>
</form>
4 - 这是anular js
app.factory('taxesSliceRepository', ['$resource', function ($resource) {
return angular.fromJson($resource('/TaxesSliced/:id', { id: '@id' }, {
update: { method: 'PUT' },
save: { method: 'POST'}
}));
}]);
app.controller('TaxesSlicedController', ['$scope', 'taxesSliceRepository', function ($scope, taxesSliceRepository) {
$scope.addTax = function () {
taxesSliceRepository.save($scope.TaxSliced);
}
}]);
当我尝试在转到服务器之前添加数据时显示此错误 因为当我将数据类型更改为字符串时,来自和将是int数据类型
POST // localhost:10168 / TaxesSliced 500(内部服务器错误)
消息“:”发生了错误。“,”ExceptionMessage“:”属性'来自' 类型'TaxSliced'无效。