Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# restfulapi:create方法不';不执行_C#_Asp.net Web Api - Fatal编程技术网

C# restfulapi:create方法不';不执行

C# restfulapi:create方法不';不执行,c#,asp.net-web-api,C#,Asp.net Web Api,我正试图创建一个restful api,如下所示 问题是,当调用链接获取对象时,它会起作用: [HttpGet] [ActionName("GetDemByID")] 但是当我试着叫这个的时候: [HttpPost] [ActionName("CreateDemByID")] 我犯了405个错误 我的路由器似乎正常: public static void Register(HttpConfiguration config) {

我正试图创建一个restful api,如下所示

问题是,当调用链接获取对象时,它会起作用:

[HttpGet]
        [ActionName("GetDemByID")]
但是当我试着叫这个的时候:

[HttpPost]
        [ActionName("CreateDemByID")]
我犯了405个错误

我的路由器似乎正常:

    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute( 
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
我是否缺少一个完整的CRUDRESTAPI? 我甚至没有在调试模式下使用该方法

我看到ActionName也可用于post方法,因此它在方法中不是问题,但在路由器或注释中

有没有比我实际使用的教程更好的教程(使用动作名称,没有EF)

编辑:正如建议的那样,这仅仅是由于Get中的调用

使用RESTClient在浏览器中进行测试,它允许我选择我想要使用的方法,现在可以正常工作了

模块在创建RESTAPI时非常有用。我想没有必要


谢谢。

对于HTTP请求,请在Ajax请求中使用此选项

Content-type: application/json 

您要请求的
url
是什么?@AmitKumarGhosh我请求第一个和第二个。显示您的
操作
签名以及如何调用该操作。如果Fiddler工作,则调用代码中存在其他问题。显示您的控制器签名以及如何调用该签名。。