Search code examples
asp.netasp.net-mvcasp.net-corerazor

@await RenderSectionAsync giving "Cannot await 'method group' "


I am creating a razor application consisting of two simple user inputs and two navigation tabs with 'save' and 'cancel' button for the user inputs. I have pasted below part of the _Layout.cshtml code giving the titled error. Am I missing something ?

    </header>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody ( )
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2023 - Landing Page
        </div>
    </footer>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>

    @await RenderSectionAsync ( "Scripts" , required: false )
</body>
</html>

Tried reading the MS CS4001 doc but there's nothing there regarding this error. Pls help. Thanks!


Solution

  • Inside the @await RenderSectionAsync ( "Scripts" , required: false ) line you have a misplaced space inside it which caused the issue.

    I suggest you could remove the space use it like below and then it will work well.

      @await RenderSectionAsync("Scripts", required: false)