Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:20:40+00:00 2026-06-02T18:20:40+00:00

/// Model public class MenuModels { public Int32 MenuId { get; set; } public

  • 0
///  Model
public class MenuModels
{
    public Int32 MenuId { get; set; }
    public string MenuName { get; set; }
    public Int32 MenuLevel { get; set; }
    public Int32 MenuParent { get; set; }
    public string MenuUrl { get; set; }
}

///    In my Controller I have this code
Menus = menuRepository.GetAll().OrderBy(y=>y.menu_id+y.menu_parent+y.menu_level).ToList()

I want to get all the menus in ascending order by sum of 3 fields(id,parentId,level).

or else concatenation of 2 fields(id,parentId)

menuRepository.GetAll().OrderBy(y=>int.parse(y.menu_id.ToString+y.menu_parent.ToString)).ToList()

Basically im creating a MENU Create Controller in that i have a dropdownlist that fills the all the menus, but i want to fill menus in dropdown like

Home
--submenu1
--submenu2
Contact
--submenu1
--submenu2

for this i have written code below

        var menuModel = new MenuModels()
        {
            Menus = menuRepository.GetAll().ToList().Select(x =>
                           {
                               var level = x.menu_level;
                               return (level == 0)
                                          ? new SelectListItem {Text = x.menu_name, Value = x.menu_id.ToString()}
                                          : new SelectListItem {Text = "-- "+x.menu_name, Value = x.menu_id.ToString()};
                           })
         };
        return View(menuModel);

But this doesn’t give me what im expecting and i know why,
in database i have table like

id   level   parent   name
---------------------------
1    0       0        Home
2    0       0        About
3    1       1        submenu1
4    1       1        submenu2
5    1       2        submenu1

i made sql query for this to get better understanding my problem

select *,( Convert(nvarchar(50),(case when menu_parent=0 then menu_id else menu_parent end))  + '' +  Convert(nvarchar (50),(menu_parent)))
 as Sort from menu order by Sort,menu_id

this query results like

id   level   parent   name      Sort
------------------------------------
1    0       0        Home       10
3    1       1        submenu1   11
4    1       1        submenu2   11
2    0       0        Abount     20
5    1       2        submenu1   22
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:20:42+00:00Added an answer on June 2, 2026 at 6:20 pm

    Use

    menuRepository.GetAll().
            select(y= new MenuDatastructure() 
            {
                //rest of the properties like menuid,menuName etc,
                sortColumn = //concat the fields to get sort column like 10,11,11,20,22
            }
            ).OrderBy(y=>y.sortColumn).ToList()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model public class MyModel { public string Name { get; set;} }
I have this model: public class Package { public string CustomerName { get; set;
I have the following Model: public class Person { public string Name {get;set;} public
I have a model public class Person { public string Name { get; set;
I have a simple Model: public class MyModel { public string Text{get;set;} } I
I have a model public class Foo{ public int Id{get;set;} public string Name {get;
I have the following Model: public class DeliveryTracking { public string TrackingRef { get;
Model: public class EmailAttachment { public string FileName { get; set; } public string
Let's have a model public class Model { public int Number { get; set;
I have following model: public class FormularModel { [Required] public string Position { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.