Created
June 3, 2019 20:50
-
-
Save sahgilbert/e006d66c9f466180f3dc4e3a0ce91420 to your computer and use it in GitHub Desktop.
C# ASP.Net Core - Unified MVC & Web Api Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
namespace SimonGilbert.Blog.Controllers | |
{ | |
public class UnifiedController : Controller | |
{ | |
[HttpGet] | |
public IActionResult Index() | |
{ | |
ViewBag.Title = "This is the 'Index' action MVC VIEW"; | |
return View(); | |
} | |
[HttpGet] | |
public IActionResult About() | |
{ | |
return Ok("This is the 'About' action WEB API endpoint"); | |
} | |
[HttpGet] | |
public string Test(string id) | |
{ | |
return $"You called the 'Test/{id}' action WEB API endpoint"; | |
} | |
[HttpPost] | |
[ProducesResponseType(StatusCodes.Status200OK)] | |
public IActionResult Send([FromBody]SendDataModel model) | |
{ | |
return Ok($"You posted {model.Data} to the 'Send' action WEB API endpoint"); | |
} | |
} | |
public class SendDataModel | |
{ | |
public string Data { get; set; } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment