Home Creating recursive method helper with Func<>
Reply: 0

Creating recursive method helper with Func<>

Jahan
1#
Jahan Published in 2018-01-11 15:53:13Z

I have two method helper with theses signatures:

@helper CreateNavigation(int parentId, int depthNavigation)

@helper Navigation(int parentId, int depthNavigation)

I have tried to convert it to a proper method for using in ASP.NET Core 2.

But I got an error in VS2017 IDE that is:

1- Use of unassigned local variable 'Navigation'
2- local variable 'Navigation' might not be initialized before accessing

How can I fix it?

@using Microsoft.AspNetCore.Html
@using Microsoft.AspNetCore.Mvc.Razor
@model List<Jahan.Beta.Web.App.Models.Comment>

@{
    Func<int, int, int, HelperResult> CreateNavigation
        = (parentId, depthNavigation) => new Func<object, HelperResult>(
    @<text>@{
                Comment parent = Model.SingleOrDefault(r => r.Id == parentId);
                depthNavigation = 6;
        @Navigation(parentId, depthNavigation)
    }</text>)(null);
}
@{

    Func<int, int, HelperResult> Navigation
        = (parentId, depthNavigation) => new Func<object, HelperResult>(
    @<text>@{
                var parent = Model.Children(parentId);
                if (//condition)
                {
                    if (//condition)
                    {
                        foreach (var comment in Model)
                        {
                            if (//condition)
                            {
                                <li><p>@comment.Description</p></li>
                                @Navigation(comment.Id, depthNavigation)
                            }
                        }
                    }
                }
    }</text>)(null);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.365882 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO