其他分享
首页 > 其他分享> > WebAPI的使用

WebAPI的使用

作者:互联网

后台API的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Cors;

namespace ECERP.Web.Controllers
{

    [RoutePrefix("api")]
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public class SignInController: ApiController
    {
        [HttpPost, Route("SignIn/SignIn")]
        public void SignIn([FromBody]SignInDto signInDto)
        {            
        }      
    }

    public class SignInDto
    {
        /// <summary>
        /// 设置的Id
        /// </summary>
        public string Id { get; set; }
    }
}

前台JS代码:

var data={Id: "1"};
$.ajax({ type: "post", url: "/api/SignIn/SignIn", data: JSON.stringify(data), cache: true, contentType: "application/json",//必须是这个 //contentType: false,//上传文件用这个 dataType: "json", success: function (data, status) { }, error: function (e) { }, complete: function () { } });

  

标签:WebAPI,Web,System,SignIn,使用,using,data,public
来源: https://www.cnblogs.com/gonghui2016/p/11579791.html