This is a migrated thread and some comments may be shown as answers.

example with menu and master pages

0 Answers 98 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
georges
Top achievements
Rank 1
georges asked on 20 Dec 2010, 10:50 PM
hi  i have a master page and i have a telerik menu on that master page

 --------------------------------------------------------------this is the master----------------------------------------------------

@using Telerik.Web.Mvc.UI
@model IEnumerable<TPRO.Models.GroupsModels>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">  
      <title>@View.Title</title>
      <link href="@Url.Content("~/Css/OtherPages.css")" rel="stylesheet" type="text/css" />
      @*
     <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    *@
    @{ Html.Telerik().StyleSheetRegistrar()
                         .DefaultGroup(group => group
                         //.Add("telerik.examples.css")
                          //.Add("telerik.common.css")
                            .Add("telerik.common.css")
                         .Add("telerik.vista.css")
                          //.Add("telerik." + Html.GetCurrentTheme() + ".css")
                         // .Add("telerik.rtl.css")
                          .Combined(false)
                          .Compress(false)).Render();
                     }
    </head>

<body>
    
     <table width="100%"  cellpadding="0" cellspacing="0" border="0">
          <tr  class="BigHeaders"><td><img alt="" src="../../images/gdot.png" /></td><td align="right" valign="bottom" >TRANSPORTATION PROJECT SYSTEM&nbsp;</td></tr>
            <tr class="windowsAuthenticationMenu"><td align="left">&nbsp;Welcome&nbsp;<label runat="server" id="lblName">@HttpContext.Current.User.Identity.Name</label></td><td align="right"><label runat="server" id="lbldate">@DateTime.Now</label></td></tr>
            <tr><td class="menu"  colspan="2">
             @(            
            
                
                 Html.Telerik().Menu()
                   .Name("Menu")
                   .BindTo(Model, mappings =>
                       {

                           mappings.For<TPRO.Models.GroupsModels>(binding => binding
                               .ItemDataBound((item, GroupsModels) =>
                               {
                                   item.Text = GroupsModels.MainTitle;

                               })

                           .Children(GroupsModels => GroupsModels.SubGroups));
                               mappings.For<TPRO.Models.SubGroupsModels>(binding => binding
                                   .ItemDataBound((item, GroupsModel) =>
                                   {
                                      item.Text = GroupsModel.Title;
                                       item.Url = Url.Action(GroupsModel.Action, GroupsModel.Controller, new { GroupsModels = GroupsModel.Action }); 
                                   }));
                           );
                       })
        )         
            
            </td></tr>
           <tr  valign="top" align="center"><td colspan="2">@RenderBody()</td></tr>
     </table>
    
   @{ Html.Telerik().ScriptRegistrar()
                     .DefaultGroup(group => group
                        // .Add("telerik.examples.js")
                         .Compress(false))
                     .Render();}
</body>
</html>


here is my controller code... how do i call my action from the master page to load the menu data? i am having an issue with razor to do that? i need the syntax please , this is the error i am getting , because the detail page i am going to has a

The model item passed into the dictionary is of type 'TPRO.Models.ActivitiesModel[]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[TPRO.Models.GroupsModels]'.
--------------------------------------------this is the page i am linking to go to and it pulls from the master--------------------------------------------

@using Telerik.Web.Mvc.UI;
@model IEnumerable<TPRO.Models.ActivitiesModel>
@using TPRO;

@{
    View.Title = "Edit Activity";
    Layout = "~/Views/Shared/Master.cshtml";
}

<table width="100%" cellpadding="0"  border="0" cellspacing="0">
       <tr><td colspan="5" style="background:#FFF8C6"  align="center"><label runat="server" id="lbltitle" class="HeaderLabels">@CommonStrings.frmEditActivity</label></td></tr>
       
        <tr style="background-color:Window">
        <td>&nbsp;</td>
        <td align="left"><label runat="server" class="controlsLabels" id="lblProjId">Project ID</label>&nbsp;@Html.TextBox("TxtProj","0000265")</td>
        <td align="right" colspan="2"><label runat="server" id="lblAcctNumber" class="controlsLabels">Project Accounting Number</label>&nbsp;@Html.TextBox("TxtAcct","HPP00-0000-00(265)")</td>
       <td>&nbsp;</td>
        </tr>
             

         <tr><td colspan="5">&nbsp;</td></tr>
        <tr><td>&nbsp;</td><td colspan="3" align="center"><label runat="server" id="lblActivity" >Activity</label>&nbsp;@Html.TextBox("TxtActivity", "00110 - develop long form-LGPA or MOU (local PE)", new { @class = "Textboxes" }) </td></tr>
         <tr><td colspan="5">&nbsp;</td></tr>
         <tr><td>&nbsp;</td><td><label id="lblStartDate">Early Start</label>&nbsp;@Html.Telerik().DatePicker().Name("DtEarlyStart")</td><td><label runat="server" id="lblExpfinish">Expected Finish</label>&nbsp;@Html.Telerik().DatePicker().Name("DtExpectedFinish")</td><td><label runat="server" id="lblActivityType">Activity Type</label>&nbsp;@Html.TextBox("TxtType","Normal")</td></tr>
         
         <tr><td>&nbsp;</td><td><label id="lblTimeNow">Time Now</label>&nbsp;@Html.Telerik().DatePicker().Name("DtTimeNow")</td><td><label runat="server" id="lblOriginalDuration">Orinigal Duration</label>&nbsp;@Html.TextBox("TxtDuration","3")</td><td><label runat="server" id="lblRemainingDuration">Remaining Duration</label>&nbsp;@Html.TextBox("TxtRemaining","3")</td></tr>
          <tr><td colspan="5">&nbsp;</td></tr>
           <tr><td colspan="5">
          
           <table width="100%" cellpadding="0"  border="0" cellspacing="0">
            <tr><td><label runat="server" id="lblpre">Predecessors</label></td><td>&nbsp;</td><td><label runat="server" id="lblSucc">Successors</label></td></tr>
            <tr>
           
            <td>
            @(
     
         Html.Telerik().Grid(Model)
         .Name("Grid")
         .DataKeys(keys => keys.Add(c => c.Activity))
        .DataBinding(dataBinding => dataBinding
             .Ajax()
             .Select("EditingServerSide", "Grid")
             .Insert("Insert", "Grid")
             .Update("Save", "Grid")
             .Delete("Delete", "Grid"))
             .Columns(columns =>
              {
                  columns.Bound(m => m.Activity).Title("Activity ID");
                  columns.Bound(m => m.Description).Title("Description");
                
              }
            )
             .Sortable()
             .Pageable(paging =>
                {
                    paging.Enabled(true);
                    paging.PageSize(5);
                }
            )
           
      
)
            </td><td>&nbsp;</td><td>
            @(
     
         Html.Telerik().Grid(Model)
         .Name("Grid")
         .DataKeys(keys => keys.Add(c => c.Activity))
        .DataBinding(dataBinding => dataBinding
             .Ajax()
             .Select("EditingServerSide", "Grid")
             .Insert("Insert", "Grid")
             .Update("Save", "Grid")
             .Delete("Delete", "Grid"))
             .Columns(columns =>
              {
                  columns.Bound(m => m.Activity).Title("Activity ID");
                  columns.Bound(m => m.Description).Title("Description");
                
              }
            )
             .Sortable()
             .Pageable(paging =>
                {
                    paging.Enabled(true);
                    paging.PageSize(5);
                }
            )
           
      
)  </td>
            </tr>
                     
           </table>
         
          
           </td></tr>       
   

       
         <tr><td colspan="5">&nbsp;</td></tr>

      

         <tr><td colspan="5">&nbsp;</td></tr>
           
</table>
 

 

-------------------------------------------------------this is the controller------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TPRO.Models;
using Telerik.Web.Mvc.UI;
using System.Collections;

namespace TPRO.Controllers
{
    public class HomeController : Controller
    {
      

        public ActionResult frmPanel2()
        {
            return View(GetGroups());
        }
       
       

        public static List<GroupsModels> GetGroups()
        {
            List<GroupsModels> ClsGroup = new List<GroupsModels>();
            GroupsModels group1 = new GroupsModels("Home","frmPanel2","Home Page","Project Management",1);
            GroupsModels group2 = new GroupsModels("Activities","frmEditActivity","Edit Activity","Funds Management",2);
            GroupsModels group3 = new GroupsModels("Activities", "frmMainActivities","Activity Selection","Right of Way",3);

            GroupsModels group4 = new GroupsModels("Home", "frmPanel2", "Home Page", "LGPA",4);
            GroupsModels group5 = new GroupsModels("Activities", "frmEditActivity", "Edit Activity", "Utility/RailRoad",5);
            GroupsModels group6 = new GroupsModels("Activities", "frmMainActivities", "Activity Selection", "Environment/Location",6);

            GroupsModels group7 = new GroupsModels("Home", "frmPanel2", "Home Page", "PNRC Projects",7);
            GroupsModels group8 = new GroupsModels("Activities", "frmEditActivity", "Edit Activity", "Reporting",8);
            GroupsModels group9 = new GroupsModels("Activities", "frmMainActivities", "Activity Selection", "Help",9);
            ClsGroup.Add(group1);
            ClsGroup.Add(group2);
            ClsGroup.Add(group3);

            ClsGroup.Add(group4);
            ClsGroup.Add(group5);
            ClsGroup.Add(group6);

            ClsGroup.Add(group7);
            ClsGroup.Add(group8);
            ClsGroup.Add(group9);

            List<SubGroupsModels> ClsSubGroup = new List<SubGroupsModels>();
            SubGroupsModels group11 = new SubGroupsModels("Home", "frmPanel2", "Home Page", "Project Management",1);
            SubGroupsModels group21 = new SubGroupsModels("Activities", "frmEditActivity", "Edit Activity", "Funds Management",2);
            SubGroupsModels group31 = new SubGroupsModels("Activities", "frmMainActivities", "Activity Selection", "Right of Way",2);

                      
            ClsSubGroup.Add(group11);
            ClsSubGroup.Add(group21);
            ClsSubGroup.Add(group31);
            

           

            foreach (GroupsModels item in ClsGroup)
            {
                foreach (SubGroupsModels item2 in ClsSubGroup)
                {
                    if (item.ID == item2.SubID)
                    {
                        SubGroupsModels ClsSub = new SubGroupsModels();
                        ClsSub.Title = item2.Title;
                        ClsSub.Action = item2.Action;
                        ClsSub.Controller = item2.Controller;
                        item.SubGroups.Add(ClsSub);
                    }

                }
            }
     

            return ClsGroup;
        }
      
    }
}


Tags
Menu
Asked by
georges
Top achievements
Rank 1
Share this question
or