Mix web api action and not use api action.

How to make one controller with a web API and not a web API on a single controller.

When I do this, I have a 404 error for a non-web API action.

I read in another article that you can mix with the ASP.NET core, but it doesn’t work.

Refund 404 for:

Or

Return 404 for http: // localhost: 5000 / api / board /

public class BoardController : Controller
{
    private IDataContext dataContext;

    public BoardController(IDataContext dataContext)
    {
        this.dataContext = dataContext;
    }

    public IActionResult Index(int boardID)
    {       
        return View();
    }

    [HttpGet]
    public IEnumerable<Board> GetAll()
    {

    }
}

I think I get the second solution and http: // localhost: 5000 / board / getall for the API action

+4
source share
1 answer

You can use:

[Route("api/[controller]")]
public class BoardController : Controller
{
    private IDataContext dataContext;

    public BoardController(IDataContext dataContext)
    {
        this.dataContext = dataContext;
    }

    [Route("/[controller]/[action]")]
    public IActionResult Index(int boardID)
    {
        return View();
    }

    [HttpGet]
    public IEnumerable<Board> GetAll()
    {
    }
}

.

+4

Source: https://habr.com/ru/post/1664265/


All Articles