发布号码数据类型时Angular的问题 [英] Problem with Angular when post number data type
本文介绍了发布号码数据类型时Angular的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1-这是我的模型
1- this is my model
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
2- this is 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 - 这个HTML页面
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
4-this is 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 http:// localhost:10168 / TaxesSliced 500(内部服务器错误)
消息:错误已发生。,ExceptionMessage:属性'来自'类型'TaxSliced'无效。
when i trying add data before go to server shows this error
becouse from and to are int data type when i changed data type to string it's works
POST http://localhost:10168/TaxesSliced 500 (Internal Server Error)
Message":"An error has occurred.","ExceptionMessage":"Property 'From' on type 'TaxSliced' is invalid.
推荐答案
resource', function (
resource', function (
resource){
return angular.fromJson (
resource) { return angular.fromJson(
resource(' / TaxesSliced /:id', {id:' @ id'},{
update:{method:' PUT'},
save:{method:' POST'}
}));
}]);
app.controller(' TaxesSlicedController',['
resource('/TaxesSliced/:id', { id: '@id' }, { update: { method: 'PUT' }, save: { method: 'POST'} })); }]); app.controller('TaxesSlicedController', ['
这篇关于发布号码数据类型时Angular的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文