Haoest
Haoest

Reputation: 13906

how to set up url routing with sub-paths

i am new to webapi and MVC in general. If I wanted to group my service URLs like this

Am I able to put all 3 method calls in the same controller file and somehow map a particular request to the right method?

Upvotes: 0

Views: 21

Answers (1)

Hussein Beygi
Hussein Beygi

Reputation: 471

Create a Controller named Account and Create 3 [GET, POST, PUT, DELETE] method and name them create , login ,resetpass. By Default, this is the routing for MVC / API(Id can be optional)
route Template: "api/{controller}/{id}",

Example :


public class AccountController : ApiController
{
        [HttpPost]
        public string Create()
        {
            // CODE
        }

        [HttpPost] // or  [HttpGet] 
        public string Login ()
        {
            // CODE
        }

        [HttpPost]
        public string Resetpass()
        {
            // CODE
        }
}


if you had trouble calling them, try to give them a specific route :

        [HttpGet("GetSubject/{subject}")]
        public int GetSubjectId(String subject)
        {

          //CODE
        }

Please if you get any error or misunderstanding, don't hesitate to post a comment

Upvotes: 1

Related Questions