如何将数据从数据库发送到kendo ui listview?

时间:2014-08-01 11:17:59

标签: asp.net-mvc kendo-ui kendo-listview

我想要cretae购物车,此页面显示库存中的所有产品。来自LISTVIEW即将来临并且它是空的/。 我的代码如下所示,listview即将来临,它是空的`:         @model IEnumerable         @ {             ViewBag.Title =“索引”;             Layout =“〜/ Views / Shared / _Layout.cshtml”;         }

    <script type="text/x-kendo-tmpl" id="template">
            <div class="product">
            <img src="@Url.Content("~/Content/Images")$#:product_name#.jpg"      alt="#:product_name# image" />
            <h3>#:product_name#</h3>
            <p>#:kendo.toString(product_price, "c")#</p>
        </div>
    </script>

    <div class="demo-section">
    @(Html.Kendo().ListView<caseStudy.Models.product>()
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        .DataSource(dataSource => {
            dataSource.Read(read => read.Action("Products_Read","Product"));
            dataSource.PageSize(15);
        })
        .Pageable()
    )

    </div>

    my controlller :

            public ActionResult Index()
            {
                return View(GetProducts());
            }

            public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
            {
                return Json(GetProducts().ToDataSourceResult(request));
            }

            private static IEnumerable<product> GetProducts()
            {
                var Plist = new ShopCartDataContext();

                return Plist.products.Select(p => new product
                {
                    product_name=p.product_name,
                    product_price = p.product_price,
                    product_id = p.product_id

                });

            }` 

1 个答案:

答案 0 :(得分:0)

尝试更新模板,如下所示:

<script type="text/x-kendo-tmpl" id="template">
        <div class="product">
        <img src="@Url.Content("~/Content/Images/")#:product_name#.jpg" 
         alt="#:product_name# image" />
        <h3>#:product_name#</h3>
        <p>#:kendo.toString(product_price, "c")#</p>
    </div>
</script>