热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

TelerikMVC控件,OnDocumentReady发射两次-TelerikMVCcontrols,OnDocumentReadyisfiringtwice

ImnewtoTelerikMVCcontrols,sothismaybesomethingsimple.我是TelerikMVC控件的新手,所以这可能很简单。Ist

I'm new to Telerik MVC controls, so this may be something simple.

我是Telerik MVC控件的新手,所以这可能很简单。

I started out with making a new TelerikMvcApplication solution.

我开始制作新的TelerikMvcApplication解决方案。

Site.Master:

    
<%: Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true).Add("Index.js")) %>

Index.aspx:

    <%: Html.Telerik().ScriptRegistrar().OnDocumentReady("Index.Init()") %>

Index.js:

var Index = function () {
    return {
        Init: function () {
            alert('1');
        }
    };
} ();

When I load Index.aspx, the Init() function in Index.js is fired twice, so I see 2 alerts one after another. If I assign a click handler to a button inside the Init() function and hit the button with FireBug, it is actually showing 2 events being assigned to the button. Why is this happening?

当我加载Index.aspx时,Index.js中的Init()函数被触发两次,所以我看到一个接一个的2个警报。如果我将一个单击处理程序分配给Init()函数内的按钮并使用FireBug点击该按钮,它实际上显示为该按钮分配了2个事件。为什么会这样?

Edit

After some more firebugging, I figured out that both calls to ScriptRegistrar are being rendered. How do I make only master one to render?

经过一番讽刺之后,我发现两个对ScriptRegistrar的调用都被渲染了。如何只制作一个渲染的主人?

2 个解决方案

#1


2  

To answer my own question, the problem was in the use of

要回答我自己的问题,问题在于使用

<%:  %>

with colon.

To fix it, I removed colon character from both Master and View, and called Render() in Master.

为了解决这个问题,我从Master和View中删除了冒号字符,并在Master中调用了Render()。

Master:

<% Html.Telerik().ScriptRegistrar().DefaultGroup(group =>
   group.Combined(true).Compress(true).Add("json2.js")).Render(); %>

View:

<% Html.Telerik().ScriptRegistrar().Scripts(scripts =>
   scripts.AddGroup("IndexGroup", group =>
   group.Add("~/Scripts/Index.js"))).OnDocumentReady("Index.Init()");  %>

#2


0  

For MVC Razor ViewEngine:

对于MVC Razor ViewEngine:

@{
    Html.Telerik().ScriptRegistrar().OnDocumentReady(
    @
        alert('onLoaded');
    );
}

推荐阅读
author-avatar
黄小翻_618
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有