InvalidOperationException: The following sections have been defined but have not been rendered by the page at '/Views/Shared/UserLayout.cshtml'

IntelligentCancer 0 Reputation points
2023-07-24T15:07:39.1166667+00:00

I'm trying to convert an ASP.NET MVC project to ASP.NET Core MVC. I have done most of the work but got stuck in a weird issue.

My project has a view User.cshtml and a layout page UserLayout.cshtml, based on an API call I was returning the view and its master page through return View("User", "UserLayout"); in ASP.NET MVC.

The method expects a view name and a master name. This overload doesn't exists anymore in ASP.NET Core MVC so I have set the layout on top of my User.cshtml page like this:

@{ Layout="~/Views/Shared/UserLayout.cshtml"; }

and returned just the view name from my controller.

Now my layout page contains Kendo tabstrip and in its content I'm rendering sections like @RenderSection("HomeTab", true) which are defined in UserLayout.cshmtl @section HomeTab {}. This is working completely fine with the ASP.NET MVC project, but when I run the ASP.NET Core MVC project, I'm getting this exception:

InvalidOperationException: the following sections have been defined but have not been rendered by the page at '/Views/Shared/UserLayout.cshtml': 'HomeTab'. To ignore an unrendered section call IgnoreSection("sectionName").

I have tried removing the section, changing the required attribute to false but the error remains. It seems I didn't need to convert views from .NET to .NET Core but it's this small thing that has got me stuck.

Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. IntelligentCancer 0 Reputation points
    2023-07-30T09:30:28.5266667+00:00

    Since I haven't found a concrete solution to having the section rendered, I copied the code of my HomeTab section from my view and inserted it directly to content section of my Kendo Tabstrip.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.