Search code examples
c#razorumbraco

Using OR operator in Razor view


Let me explain my scenarios. I'm building a multi site umbraco site. I got two type of homepage content type alias. (Assume XXXX and YYYY). I'm using var homePage in my common NavMain.cshtml partial view. How can I achieve something like following

var homePage = Model.Root().FirstOrDefault(x => x.ContentType.Alias == "XXXX" || x => x.ContentType.Alias == "YYYY");

Solution

  • Did you try:

    var homePage = Model.Root().FirstOrDefault(x => x.ContentType.Alias == "XXXX" || x.ContentType.Alias == "YYYY");
    

    See the following article for the correct syntax: Expression lambdas