namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AnimalsController : ControllerBase
{
public IActionResult GetAnimals();
{
var animals = new List<AnimalModel>
{
new AnimalModel() { Name = "dog", Description = "4 legs"};
new AnimalModel() { Name = "cat", Description = "4 legs" };
};
return Ok(animals);
}
}
}
-
3Please post code as code, not as images.Jeroen Mostert– Jeroen Mostert2022-09-06 09:41:51 +00:00Commented Sep 6, 2022 at 9:41
-
2Add your code instead of images please.Amal Ps– Amal Ps2022-09-06 09:46:39 +00:00Commented Sep 6, 2022 at 9:46
-
2You should probably read How to ask before posting.JonasH– JonasH2022-09-06 09:49:50 +00:00Commented Sep 6, 2022 at 9:49
-
You seem to have a thing for semi-colons, try removing some.phuzi– phuzi2022-09-06 09:52:13 +00:00Commented Sep 6, 2022 at 9:52
-
try my code......Tiny Wang– Tiny Wang2022-09-06 09:52:43 +00:00Commented Sep 6, 2022 at 9:52
Add a comment
|
2 Answers
[Route("api/[controller]")]
[ApiController]
public class AnimalsController : ControllerBase
{
public IActionResult GetAnimals()
{
var animals = new List<AnimalModel>
{
new AnimalModel() { Name = "dog", Description = "4 legs"},
new AnimalModel() { Name = "cat", Description = "4 legs" }
};
return Ok(animals);
}
}
public class AnimalModel
{
public string Name { get; set; }
public string Description { get; set; }
}
