Telerik MVC ScriptRegistrar 复制 javascript
我正在尝试注册一些 JavaScript,但我似乎遇到了问题。在我的母版页底部,我有:
@(
Html.Telerik().ScriptRegistrar()
.OnDocumentReady(@<text>
// Open the hidden window when the feedback-link is clicked
$('#feedback-link').click(function(e) {
e.preventDefault();
$('#FeedbackWindow').data('tWindow').center().open();
});
</text>)
)
在我的视图中,我想要一些特定于视图的 javascript,所以我有:
@(Html.Telerik().ScriptRegistrar().OnDocumentReady(
@<text>
// Upon contact selection change, update the contact sidebar summary
$('#contactlist').change(function() {
alert('Selected id' + $(this).val());
});
</text>)
)
不幸的是,这导致我的视图的 javascript 在 MVC 视图和我的母版页中都被声明最终页面已呈现。我怎样才能让它只注册一次脚本?
I am attempting to register some javascript in my view, and I seem to be having an issue. In my master page, at the bottom I have:
@(
Html.Telerik().ScriptRegistrar()
.OnDocumentReady(@<text>
// Open the hidden window when the feedback-link is clicked
$('#feedback-link').click(function(e) {
e.preventDefault();
$('#FeedbackWindow').data('tWindow').center().open();
});
</text>)
)
In my view, I want some view specific javascript, so I have:
@(Html.Telerik().ScriptRegistrar().OnDocumentReady(
@<text>
// Upon contact selection change, update the contact sidebar summary
$('#contactlist').change(function() {
alert('Selected id' + $(this).val());
});
</text>)
)
Unfortunately, this is causing my view's javascript from being declared both in the MVC view, and in my master page when the final page is rendered. How can I get this to only register the script once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在我的 论坛回复 ScriptRegistrar 被输出两次,因为如此告知。
@()
Razor 表达式将输出其内容,而@{ }
将被执行。在您的情况下,您需要对特定脚本使用@{ }
:另请注意,
@{ }
块需要分号。As I said in my forum reply the ScriptRegistrar is being output twice because told so. The
@()
Razor expression will output its contents whereas@{ }
will be executed. In your case you need to use@{ }
for the specific script:Also note that the
@{ }
block requires a semi-colon.