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

[Solved] MVC3 - Partial Views

2 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Les
Top achievements
Rank 1
Les asked on 03 Mar 2011, 08:24 PM
Hi Guys, I have a small problem which I hope you can be of assistance with. I have a partial view to which I want to pass the name of an EntityFramework Object, to which the Grid will bind.

<fieldset>
       <!-- Telerik Grid Control -->
       <legend>Classifications</legend>
               @(Html.Telerik()
               //Bind Grid to Type 'ClassificationViewModel'
               .Grid<"Entity Name">()
               .Name(TempData["Name"])
                       //.PrefixUrlParameters(false)
               .Pageable(pager => pager.PageTo(1).Position(GridPagerPosition.Bottom))
                       //{ Note: paging =>
                       //    paging.Enabled(true);
                       //    paging.PageSize(50);
                       //}
                       //org .DataKeys(keys => keys.Add(dataKeys => dataKeys.ClassificationID))
               .DataKeys(keys => keys.Add(dataKeys => dataKeys.ID))
               .ToolBar(ToolBarCommand => ToolBarCommand
                   //.Custom().Text("Edit").Action("AjaxIndex","Classification")

Can you please tell me what in your oppinion the best practice is to pass the Entity Object Name to ..
Grid<".....">()

As ever, thank You for your help.

Les

2 Answers, 1 is accepted

Sort by
0
Les
Top achievements
Rank 1
answered on 06 Mar 2011, 09:58 PM
Hi,

Further to my previous email.. what I am hoping to achieve is to have the Grid in a single partial view, which I can render from any View in my application and pass a class as argument to the partial view. It is working fine when I have the Grid in the same View which is being rendered, but when I use a partial view, the fun starts :).

How can this be achieved in MVC3 using Razor? I have been trough the forums, web and cannot find a working solution.

Les
0
Les
Top achievements
Rank 1
answered on 07 Mar 2011, 12:13 AM
Hi,

I finally found a demo using the 'dynamic' type, however DataKeys property keeps throwing an exception. I noticed another user posted the same behaviour in another thread, without resolution.

@model

 

IEnumerable<dynamic>

<fieldset>

 

      <!-- Telerik Grid Control -->
      <legend>Classifications</legend>
              @(Html.Telerik()
              //Bind Grid to Type 'ClassificationViewModel'
              .Grid(Model)
              .Name(TempData["Name"].ToString())
                      //.PrefixUrlParameters(false)
              .Pageable(pager => pager.PageTo(1).Position(GridPagerPosition.Bottom))
                      //{ Note: paging =>
                      //    paging.Enabled(true);
                      //    paging.PageSize(50);
                      //}  

                   .DataKeys(dataKeys => dataKeys.Add(

 

"ClassificationID"))

 

 

 

 

              
The error I am receiving is .. 'object' does not contain a definition for 'ClassificationID'.

Records are being returned in the following fashion..
static IList<ClassificationViewModel> Read()
{
    IList<ClassificationViewModel> result = (IList<ClassificationViewModel>)System.Web.HttpContext.Current.Session["Classification"];
    if (result == null)
    {
        ContextFactory _factory = new ContextFactory();
        var _entityClassification = _factory.GetDataRepository<tbl_AssetClassification>().ReadAll();
        
        System.Web.HttpContext.Current.Session["Classification"] = result =
            (from classification in _entityClassification
              
             select new ClassificationViewModel
             {
                ClassificationID = classification.Id,
                ClassificationName = classification.Classification
             }).ToList();
    }
      
//Return the database records
return result;
}


Is this something you have resolved in the past?

Les
Tags
Grid
Asked by
Les
Top achievements
Rank 1
Answers by
Les
Top achievements
Rank 1
Share this question
or