I am building a web app using ASP.NET MVC5. I have logic for validating the route value similar to the following.
[HttpGet]
public ActionResult Books(string name)
{
if(!CheckBook(name))
{
return RedirectToAction(Index);
}
return View(model:name);
}
private bool CheckBook(string name)
{
var exists = false;
var allBooks = Library.Books; // Library is a static class and Books returns a list with all the book names
foreach(var book in allBooks)
{
if(book == name)
{
exists = true;
}
}
return exists;
}
Is it a bad practice to validate the route value in the controller? Should I create a folder such as validators and add validation functions there? Or is this where I create services? I learned that I shouldn't add business logic in controllers, so I am unsure.