Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# ASP.Net Core - Unified MVC & Web Api Controller
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
You can’t perform that action at this time.