Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pat 124 posts 346 karma points
    Jun 07, 2017 @ 10:02
    pat
    0

    sort data in a table using actionlink lose master layout

    Hi experts i am listing data using a List

    this sort my data but page load the data table in empty layout (no master layout with navigation menus and rest.)

    below table heading actionlink

       <td class="mylisttableheader">@Html.ActionLink("Name", "SortSites", new {sortOrder = ViewBag.NameSortParm })</td>
    
    
      @foreach (var item in list)
                    {
                        <tr>
                            <td>@item.name </td>
                            <td>@item.shortname</td>
    

    in my surfacecontroller

          [HttpGet]
                public ActionResult SortSites(string sortOrder)
                {
    
                    TempData["result"] = "No sites";
                    try
                    {
                        var m = Membership.GetUser();
                        if (m != null)
                        {
                            bool getdata = false;
                            var list = new List<myCodeProject.Models.SiteModel>();
                            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
                            ViewBag.SNameSortParm = sortOrder == "shortname" ? "shortname_desc" : "shortname";
    
                            if (ViewBag.sites != null)
                            {
                                list = (List<myCodeProject.Models.SiteModel>)ViewBag.sites;
                                getdata = true;
                            }
                            else
                            {
    
                                string myaccountid = "";
                                string mycontactid = "";  
    
    //    generate instance of ms1
                                _myContact myc = ms1.check_email_on_login(m.Email, myHelper.read_request_key());
                                if (myc.isValid_result)
                                {
    
                                    myaccountid = myc.parentaccountid;
                                    mycontactid = myc.contactid;
                                    _summaryAccount[] sitelist = ms1.list_sites_for_customer(myaccountid, mycontactid);
    
                                    if (sitelist != null)
                                    {
                                        foreach (_summaryAccount a in sitelist)
                                        {
                                            var s = new SiteModel();
                                            s.name = a.name;
                                            s.shortname = a.shortname;
                                            s.address1_line1 = a.address1_line1;
                                            s.address1_line2 = a.address1_line2;
                                            s.address1_city = a.address1_city;
                                            s.address1_county = a.address1_county;
                                            s.address1_postalcode = a.address1_postalcode;
                                            s.accountid = a.id;
                                            s.parentSite = a.parentidname;
                                            s.primarycontact = a.primarycontactidname;
                                            s.parentSiteid = a.parentid;
    
                                            list.Add(s);
                                        }
    
                                        TempData["result"] = "found sites";
    
                                        getdata = true;
                                       // ViewBag.sites = list;
    
                                    }
    
                                }
    
                            }
    
                            if (getdata)
                            {
                                switch(sortOrder)
                                {
                                    case "name_desc":
    
                                        ViewBag.sites = list.OrderByDescending(x => x.name ).ToList<SiteModel>();
                                        break;
                                    case "shortname":
                                        ViewBag.sites = list.OrderBy(x => x.shortname).ToList<SiteModel>();
                                        break;
                                    case "shortname_desc":
                                        ViewBag.sites = list.OrderByDescending(x => x.shortname).ToList<SiteModel>();
                                        break;
                                    default:
                                        ViewBag.sites = list.OrderBy(x => x.name).ToList<SiteModel>();
                                        break;
                                }
                            }
    
                        }//if member logged in 
                    }
                    catch (Exception ex)
                    {
    
    
                    }
    
    
                    return  PartialView("~/Views/Partials/ListSites.cshtml", new SiteModel());
    
    
    
                }
    

    this return sorted data but I lost the master templates of my web site .... how to sort this please

Please Sign in or register to post replies

Write your reply to:

Draft