2017-09-21 5 views
1

Dans mon ASP.NET MVC (6) Web APIs Web Je neWebAPI: Get api/enregistrement/id/Tags

[Produces("application/json")] 
[Route("api/Record")] 
public class RecordController : Controller 
{ 

    // ... 

    // GET: api/Record/5 
    [HttpGet("{id}", Name = "GetRecord")] 
    public async Task<Record> Get(string id) 
    { 
     var record = await repository.GetAsync<Record>(id);    
     return record; 
    } 

Maintenant, mon Record contient une Tags.

Je voudrais revenir ces balises par api/Record/5/Tags

Comment devrais-je écrire mon action dans ce cas?

Répondre

0

Si l'on suppose qu'il est une propriété au dossier créer un modèle d'itinéraire pour correspondre à l'itinéraire souhaité et retourner les étiquettes lorsqu'ils sont appelés

[HttpGet("{id}/Tags")] // GET: api/Record/5/Tags 
public async Task<IActionResult> GetTags(string id) { 
    var record = await repository.GetAsync<Record>(id); 
    if(record == null) return NotFound(); 
    return Ok(record.Tags); 
} 
+0

si un retour WebAPI retour JSON NotFound() ou Ok()? – Serge