一个模板中的MVC帮手 [英] MVC helper inside a template

查看:141
本文介绍了一个模板中的MVC帮手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个剑道MVC帮手模板内(远程模板文件加载像:的 http://docs.kendoui.c​​om/howto/load-templates-external-files#remote-templates 。我有一个控制器发送给客户端生成的标记)

I am trying to use a kendo MVC helper inside a template (remote template file loaded like: http://docs.kendoui.com/howto/load-templates-external-files#remote-templates. I have a controller that sends to the client the generated markup)

我的模板文件是这样的:

My template file is something like:

<script id="my-pager-template" type="text/x-kendo-template">
    My pager

    @(Html.Kendo().ListView<Business.Data.MyPage>()
        .Name("myPagerListView")
        .TagName("div")
        .ClientTemplateId("my-pager-item-template")
        .DataSource(dataSource => dataSource.Read(read => 
            read.Action("GetMyPages","Page")
            )
        ).ToClientTemplate())

</script>

<script id="my-pager-item-template" type="text/x-kendo-template" >
    <div class="k-button" data-pager-item-pageid="${PageID}" data-pager-item-pagename="${Name}">
        <span>${ButtonText}</span>
    </div>
</script>

不过,生成的标记是给我一个未捕获的SyntaxError:意外的令牌LT; 在我的浏览器控制台(铬)

But the generated markup is giving me an Uncaught SyntaxError: Unexpected token < in my browser console (chrome).

由助手生成的标记是这样的:

The markup generated by the helper is like this:

<div id="myPagerListView"></div>
<script>
    jQuery(function(){jQuery("\#myPagerListView").kendoListView({"dataSource":{"transport":{"prefix":"","read":{"url":"/Page/GetMyPages"}},"serverPaging":true,"serverSorting":true,"serverFiltering":true,"serverGrouping":true,"serverAggregates":true,"type":"aspnetmvc-ajax","filter":[],"schema":{"data":"Data","total":"Total","errors":"Errors","model":{"fields":{"PageID":{"type":"number"},"Name":{"type":"string"},"ButtonText":{"type":"string"}}}}},"template":kendo.template($('\#my-pager-item-template').html())});});
<\/script>

</script>

我可以用剑道佣工这种方式?
(在这篇文章中,它说,它可用于:我可以用模板内的剑道MVC佣工

推荐答案

我有这个确切的问题也。我已经认识到(在过去三小时:(),这是因为我用ajax那么jQuery文档的功能,因为它试图比执行解析加载模板文件,该错误是在jQuery的功能发生。已经错位未知原因被剑道模板文件。
(逃避该脚本代码,并在我的情况下插入按钮空间)剑道其自主时候
Fortunatly尝试使用它的工作模板。

为了解决这个问题,我直接呈现局部视图页面上。

I had this exact issue also. I have come to realise (over the past 3 hours :( ) that this is because I was using ajax then the jquery html function to load the template file and that the error was happening with in jquery's function as it tried to parse than execute the template file which has been mangled for an unknown reason by kendo.
(escaping that script tag and in my case inserting buttons in that space).
Fortunatly when kendo Its self tries to use the template it does work.
To get around this problem I rendered the partial view directly on the page.

希望这有助于。

这篇关于一个模板中的MVC帮手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆