[RESOLVED]Error in Sending Data to a Page

Guys, I made this navbar in my layout that takes the items from Database.

<ul>
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    @foreach (var item in db.Categories)
                    {
                        <li>
                            @Html.ActionLink(@item.CategoryName, "Category", "Home", new { id = item.CategoeyId })
                            <ul>
                                @foreach (var subcategory in db.SubCategories.Where(x => x.CategoryId == item.CategoeyId))
                                {
                                    <li>@Html.ActionLink(subcategory.SubName, "Content", "Home", new { id = subcategory.SubId })</li>
                                }
                            </ul>
                        </li>
                    }
                </ul>

but in this line:

@Html.ActionLink(@item.CategoryName, "Category", "Home", new { id = item.CategoeyId })

it doesn’t send the id like:  Home/Category/id

it sends the Home/Category?Length=4

What is the problem in my Routings?

max-designer

@Html.ActionLink(@item.CategoryName, "Category", "Home", new { id = item.CategoeyId },null)

@foreach (var item in db.Categories)

Can I change it into something like this: 

@foreach (var item in db.Categories.Where(x => x.MenuOption == true))

or Something like it?

Of course. However, it is not considered best practice accessing database from views

Leave a Reply