zHaytam / SmartBreadcrumbs

A utility library for ASP.NET Core (both MVC and Razor Pages) websites to easily add and customize breadcrumbs.
https://blog.zhaytam.com/2018/06/24/asp-net-core-using-smartbreadcrumbs/
MIT License
161 stars 77 forks source link

System.InvalidOperationException: 'Sequence contains no matching element' #101

Open jylaila opened 2 years ago

jylaila commented 2 years ago

This is my class in razor

[Breadcrumb("createdrequests")] public partial class CreatedRequests { }

and I´m having this issue: System.InvalidOperationException: 'Sequence contains no matching element'

madeyellow commented 2 years ago

For all those who have same issue - try to add DefaultBreadcrumb attribute on your homepage action, e.g.:

[Route("/")]
public class HomeController : Controller
{
        [DefaultBreadcrumb]
        public IActionResult Index()
        {
            return View();
        }
}

This should solve your problem with 'Sequence contains no matching element' error.

oflahero commented 2 years ago

Thanks, madeyellow - now I have System.InvalidOperationException: 'Sequence contain more than one matching element' :D

madeyellow commented 2 years ago

Thanks, madeyellow - now I have System.InvalidOperationException: 'Sequence contain more than one matching element' :D

Most likely it's because you have more than one [DefaultBreadcrumb] attribute in project. Check all your controllers and ensure that you have only one DefaultBreadCrumb attribute, which is by the way should be action, that renders main (home) page. For all other actions you should use [Breadcrumb] attribute instead (as in your original post from 17 March).

oflahero commented 2 years ago

Thanks (I'm not the OP though!) Fixed my issue anyway - was mixing Razor pages with controllers'n'views in my project, so cleared up that extra cruft and it's OK now.