Generating links using route names in asp net web api04:33

  • 0
Published on May 9, 2017

Text version of the video

Slides

All ASP .NET Web API Text Articles and Slides

All ASP .NET Web API Videos

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

To generate links in ASP.NET Web API using route names
1. Set a name for the route using the Name property of the [Route] attribute

[Route(“{id:int}”, Name = “GetStudentById”)]
public Student Get(int id)
{
return students.FirstOrDefault(s =] s.Id == id);
}

2. Use the name of the route to generate the link

public HttpResponseMessage Post(Student student)
{
students.Add(student);
var response = Request.CreateResponse(HttpStatusCode.Created);
response.Headers.Location = new Uri(Url.Link(“GetStudentById”, new { id = student.Id }));
return response;
}

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

https://iavec.com.br/

Enjoyed this video?
"No Thanks. Please Close This Box!"