asp.net-mvc
  • kendo-ui
  • kendo-asp.net-mvc
  • 2013-04-15 90 views 0 likes 
    0

    我想为ListView创建自定义模板(我在ListView中显示产品eShop)。我写了这段代码:为KendoUI创建自定义模板ListView

    <script type="text/x-kendo-tmpl" id="template"> 
        <div class="item"> 
        <div class="image"> 
         <a href='@Url.Action("GetDetails", "Products", routeValues: new {id =${ProductID}})' target='_blank' class='pimg'> 
          <img src="${ProductThumbnailImageUrl}" alt=" ${ProductTitle}"/> 
         </a> 
        <div class="price"> ${kendo.toString(ProductPrice, "n0")} </div> 
    
        <div class="name"> 
    
    </div> 
        <div class="description_featured" style="min-height: 110px;"> 
         ${ProductDescription} 
    
        </div> 
        </div> 
    </div> 
    
    </script> 
    
    @(Html.Kendo().ListView(Model) 
          .Name("listView") 
          .TagName("div") 
          .ClientTemplateId("template") 
          .DataSource(dataSource => 
             { 
              dataSource.Read(read => read.Action("Products_Read", "Products")); 
              dataSource.PageSize(12); 
              dataSource.ServerOperation(false); 
             }) 
          .Pageable() 
          ) 
    

    我在new {id = ${ProductTitle}}上遇到了一个错误。

    +0

    请检查您添加完所有需要的应用程序剑道和jQuery引用。你的模板应该在。我希望你不要错过这些! – HaBo

    +0

    @ HaBo:谢谢你帮助我。我编辑代码。请帮帮我。谢谢 – Pouya

    +0

    你有一个控制器“产品”,它有行动方法“Products_Read”,它是否返回带有属性“ProductTitle”,“ProductThumbnailImageUrl”,“ProductPrice”和“ProductDescription”的对象? – HaBo

    回答

    2

    这就是你如何使用模板。 这是我最近用于我的网站的模板。

    <script type="text/x-kendo-tmpl" id="template"> 
         <div class="product"> 
          <img src='http://cdn.rbgx.net/images/skybazaar/products/medium/${ImageFileName}' alt="${Name} image" /> 
        <div class="productDeatails"> 
          <h3>#:Name#</h3> 
        # if (EntityType == 2) { # 
         Click to see products of this category 
        # } else if(EntityType == 1) { # 
        # if(parseFloat(SalePrice) > 0 && parseFloat(SalePrice) < parseFloat(Price)) { # 
        Sale Price #: kendo.toString(SalePrice, "c")# 
        # } else { # 
        Price #: kendo.toString(Price, "c")# 
        # } # 
        # } # 
         </div> 
         </div> 
        </script> 
    

    你的情况为${ProductTitle} 使用#: ProductTitle #

    相关问题