web api post

这是显示端

function load() {
$.ajax({
type: "post",
url: "http://localhost:63211/api/MeetingRoomService/AddMeetiongType",
dataType: "json",
data: { "Typename": "123" },
success: function (data) {
renderContactList(data);
alert(data.data);
},error: function (XMLHttpRequest, textStatus, errorThrown) {

alert(data.data);
}
});
}

这是服务端

[HttpPost]
public ResultEntity<bool> AddMeetiongType([FromBody]MeetingType mt)
{
ExceptionManager.Handle(new Exception("TypeName>>>>>>" + mt.Typename));
ResultEntity<bool> result = new ResultEntity<bool>();
result.errors = new List<ErrorEntity>();
ErrorEntity error = new ErrorEntity();
result.action_code = ActionCode.SUCCESS.ToString();
try
{
Check.CheckParameter(mt.Typename);
if (bll.GetMeetingRoomTypeExist(mt.Typename) == false)
{
if (bll.AddMeetingRoomType(mt.Typename))
{
error.message = "插入成功";
result.data = true;

}
else
{
result.action_code = ActionCode.FAILED.ToString();
error.message = "插入失败";
result.data = false;

}
}
else
{
result.action_code = ActionCode.FAILED.ToString();
error.message = "此信息已经存在";

}


}
catch (ArgumentException e)
{
ExceptionManager.Handle(e);
result.action_code = ActionCode.FAILED.ToString();
error.message = e.Message;
}
catch (Exception ex)
{
ExceptionManager.Handle(ex);
result.action_code = ActionCode.FAILED.ToString();
error.message = "添加类型接口出错了!";
}
result.errors.Add(error);
return result;
}

第一个 web api post的程序

今天居然忘记了判断一个dataset是否为空的方法

ds.Tables[0].Rows.Count >0

转载于:https://www.cnblogs.com/Demcia/p/3865870.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值