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 8785543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:23:48+00:00 2026-06-13T21:23:48+00:00

Hi all i have a string like this which i am passing an ajax

  • 0

Hi all i have a string like this which i am passing an ajax function to my controller action method

       Brand1~1001=>undefined_undefined|
           Category1~2001=>1001_Brand1|
           Category2~2002=>1001_Brand1|
                  Product3~3003=>2002_Category2|
                      Product4~3004=>Product3~3003|
                 Product5~3005=>2002_Category2|
                 Product6~3006=>2002_Category2|

and i have an Menus table in db i had added that as an entity model to my project

       Menus

          [MenuID],[MenuName],[ParentID]

and i have model like this

           public class MenuItems
            {
              public List<MenuItems> GetALL { get; set; }
              public int MenuId { get; set; }
              public string MenuName { get; set; }
              public int parentId { get; set; }
            }

now i want to split the string i have and insert into the above table like this

           [MenuID],[MenuName],[ParentID]
            1001   ,Brand1    ,null
            2001   ,category1 ,1001
            2002   ,category2 ,1001
            3003   ,product3  ,2002
            3004   ,product4  ,3003
            3005   ,product5  ,2002
            3006   ,product6  ,2002

in the above string Brand1~1001=>undefined_undefined| here Brand1~1001 is the parentmenu and 1001 is the id of the menu
Category1~2001=>1001_Brand1| and here Category1~2001 is the sub menu of the 1001_Brand1 i think you all got waht i amtrying to do can any one help me here please

what i amtrying

    public ActionResult MenuDrag()
    {
        return View();
    }
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult MenuDrag(string menustring)
    {
        if (!String.IsNullOrEmpty(menustring))
        {
            string[] menus = menustring.Split('|');
            foreach (var m in menus)
            {
                string[] list = m.Split('>'); 
                //stuck from here confused what to do next and how do i insert the data in my accordingly
            }
        }

        return View();
    }
  • 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-13T21:23:49+00:00Added an answer on June 13, 2026 at 9:23 pm

    You are almost there just replace your post method with this

          [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult MenuDrag(string menustring)
        {            
            MenuItems items = new MenuItems();
          //check the string for empty
            if (!String.IsNullOrEmpty(menustring))
            {
                string[] menus = menustring.Split('|');
                foreach (var m in menus)
                {
                    if (m != "")
                    {
                        string[] list = m.Split('>');
    
    
                        string[] menu = list[0].Split('~');
                        string[] parents = list[1].Split('~');
                        items.MenuItemID = Convert.ToInt16(menu[1]);
                        items.MenuName = menu[0].ToString();
                        if (parents[0] == "undefined")
                        {
                            items.ParentID = 0;
                            db.MenuItems.Add(items);
                            db.SaveChanges();
                        }
                        else
                        {
                            int parentid=Convert.ToInt16(parents[0]);
                            var menuid = from me in db.MenusMains where me.MenuItemID == parentid select new { MenuID = me.MenuID };
                            foreach (var id in menuid)
                            {
                                items.ParentID = Convert.ToInt16(id.MenuID);                               
                            }
                            db.MenuItems.Add(items);
                            db.SaveChanges();
                        }                      
                    }
                }
            }
            return View();
        }
    
    }
    

    i had used

              if (m != "")
                {
                }
    

    since u may get an index out of bound exception there since when in your string at this

      string[] menus = menustring.Split('|');
    

    u will get an empty (‘|’) you have to handle this

    hope this works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
If I have a string of HTML, maybe like this... <h2>Header</h2><p>all the <span class=bright>content</span>
I have a JSON string which I'm passing to a function. The string is
Let's say I have the string Hey . I would like to determine all
I have a string which contains only numbers. Now I want to remove all
I have this string: var someString = 23/03/2012; and want to replace all the
i have a string which has the following format (3,1,Mayer,Jack). I need all 4
I have a following vb.net function as below in which i am passing a
I have a paragraph, which I would like to edit using javascript prompt function.
I have this API function: public ResultEnum DoSomeAction(string a, string b, DateTime c, OtherEnum

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.