【问题标题】:Kendo Grid and ASP.NET MVC4 wrapper and Conditional .ToClientTemplate()Kendo Grid 和 ASP.NET MVC4 包装器和条件 .ToClientTemplate()
【发布时间】:2012-12-24 02:00:38
【问题描述】:

我想将我的网格放在部分中,并为每个传递数据并指定是否应将网格呈现到客户端模板的网格视图都有一个强类型模型。

例如:

--MODEL
    class ProductGridModel
    {
      public List<Products> Products{get;set;}
      public bool LoadAsChildGrid{get;set;}
      public string ParentGrid {get;set;}
    }
--VIEW
    @(Html.Kendo().Grid<Models.ProductGridModel>()
    {
        .Ajax()
        .Read(read => read.Action("GetProducts", "Products", new 
            { orderID=(@Model.LoadAsChildGrid)?"#=OrderID":@Model.OrderID }))
    ...
        .ToClientTemplate(@Model.LoadAsChildGrid)//!!!<-- This can't be done
        .Events(e => e.DataBound((@Model.LoadAsChildGrid)?"BaseGridOnDataBound('grdProducts_#=OrderID#')":""))
    }
--CONTROLLER
    public ActionResult GetProducts(int orderID, [DataSourceRequest] DataSourceRequest request)
    {          
        try
        {
            base.RequireAuthorization(xxxx.StockAdmin, orderID);
            List<Products> products= new ProductManagement().GetProductsByOrderID(orderID);
            return Json(products.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        catch (Exception e)
        {
            ModelState.AddModelError("", e.ToString());
            throw e;
        }
    }

有没有办法选择性地渲染 ToClientTemplate???。如果没有解决方法,那么我唯一的选择是实现自定义 HTmlHelper KendoGridBuilder:

public virtual GridBuilder<T> Grid<T>() where T : class;

,我现在不想这样做。如果我必须扩展和实现网格,我一直在寻找关于如何完成的分步指南。任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net-mvc razor asp.net-mvc-4 kendo-ui


    【解决方案1】:

    试试这个:

    @{
     var grid = (Html.Kendo().Grid<Models.ProductGridModel>()
              ...
           );
    }
    
    @if(@Model.LoadAsChildGrid) {
      @grid.ToClientTemplate()
    } else {
      @grid
    }
    

    【讨论】:

    • 简直令人抓狂。有时最明显的解决方案是最后找到的解决方案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多