title: How to call funtions defined in controller in asp.net core razor pages project
body: <p>I am new to asp.net core and i am exploring different ways to make api calls to function defined in controller.</p>
  
  <p>I have a basic news controller as below, if i keep only one function in this controller <code>GetAll()</code> then i am able to make successful call to api using <code>https://localhost:44364/api/news</code></p>
  
  <p>and when i add other two function then same <code>https://localhost:44364/api/news</code> gets error message as below which is quite obvious as i am not making not mentioning function name in my url.</p>
  
  <p>My question is how can i define route for each function so that i can call each of these function by url and from ajax function</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code> BookListRazor.Controllers.NewsController.GetSingleNews (BookListRazor)
      BookListRazor.Controllers.NewsController.GetAll (BookListRazor)
      BookListRazor.Controllers.NewsController.GetAllNews (BookListRazor)
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code> using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Threading.Tasks;
      using BookListRazor.Model;
      using Microsoft.AspNetCore.Mvc;
      using Microsoft.EntityFrameworkCore;
  
      namespace BookListRazor.Controllers
      {
          [Route("api/News")]
          [ApiController]
          public class NewsController : Controller
          {
              private readonly ApplicationDbContext _db;
  
              public NewsController(ApplicationDbContext db)
              {
                  _db = db;
              }
  
              //get all news by languageID
              [HttpGet]
             // [Route("api/news/getallnews/{1}")]
              public async Task&lt;IActionResult&gt; GetAllNews(int langID)
              {
                  //var query = await _db.News.OrderByDescending(x =&gt; x.NewsDate).Where(x =&gt; x.LanguageID == 1 &amp;&amp; x.NewsActive==true &amp;&amp; x.NewsVisible==true).ToListAsync();
  
                  return Json(new { data = await _db.News.OrderByDescending(x =&gt; x.NewsDate).Where(x =&gt; x.LanguageID == langID &amp;&amp; x.NewsActive == true &amp;&amp; x.NewsVisible == true).ToListAsync() });
              }
  
              //get all news 
              [HttpGet]
              public async Task&lt;IActionResult&gt; GetAll()
              {
                  return Json(new { data = await _db.News.OrderByDescending(x =&gt; x.NewsDate).Where(x =&gt; x.LanguageID == 1 &amp;&amp; x.NewsActive == true &amp;&amp; x.NewsVisible == true).ToListAsync() });
              }
  
  
              //get single news by newsID
              [HttpGet]
              public async Task&lt;IActionResult&gt; GetSingleNews(int id)
              {
                  return Json(new { data = await _db.News.FirstOrDefaultAsync(x=&gt;x.NewsID == id) });
              }
  
          }
      }
  </code></pre>