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);
}
}
}
Tiny Wang
16.7k2 gold badges21 silver badges38 bronze badges
-
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
2 Answers 2
- remove the semicolon in line 13
- remove the semicolon in line 15, and 16 add (comma),
then try to execute it
answered Sep 6, 2022 at 9:49
[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; }
}
answered Sep 6, 2022 at 9:51
lang-cs