POST API ASP.Net C# (MVC)
API Controller
public class MyapiController : ApiController
{
// GET
api/myapi
public MyapiController() { }
// POST
api/myapi
public IHttpActionResult Postdata([FromBody] NotificationModel data)
{
UserRepository obj = new UserRepository();
string ErrMsg="";
obj.AddNotesDB(data, ref ErrMsg);
return Ok();
}
}
WebApiConfig.cs
public class WebApiConfig
{
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
}
);
}
}
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
No comments:
Post a Comment