剃刀/ JavaScript和尾随分号 [英] Razor/JavaScript and trailing semicolon

查看:107
本文介绍了剃刀/ JavaScript和尾随分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2012,剃刀视图页上,在JavaScript部分,我得到什么,我认为是剃刀语法之间的战斗VS JavaScript语法。特别是,在该脚本部分尾随分号由智能感知和编译器警告(未误差)被输送被判


  

警告13语法错误。


如果我删除它,然后我得到一个语句终止建议( ReSharper的在这种情况下,只是很好的做法)。

 <脚本类型=文/ JavaScript的>
    $()。就绪(函数(){
        VAR的客户= @ Html.Raw(ViewBag.CustomerJSON); //< - 剃须刀(我认为)不喜欢这个分号
    });
< / SCRIPT>

这是在剃刀的错误吗?如果是这样,是有办法,我可以改写这个来避免这个问题?


解决方案

  

这是在剃刀的错误吗?


绝对不是。运行应用程序,它会正常工作。

它是工具,你正在使用中的错误(视觉 &工作室NBSP; 2012年,ReSharper的,...)都不能确认完全有效的语法,并警告你的东西,你不应该被警告的。你可以尝试在Microsoft Connect站点打开的问题和信令这个bug如果尚未完成。

Using Visual Studio 2012, on a Razor view page, in the JavaScript section, I am getting what I think is a battle between Razor syntax vs JavaScript syntax. In particular, the trailing semicolon in the script section is flagged by intellisense and a compiler warning (not error) is delivered:

'Warning 13 Syntax error'.

If I remove it, then I get a statement termination recommendation (ReSharper in this case, but just good practice).

<script type="text/javascript">
    $().ready(function(){
        var customer = @Html.Raw(ViewBag.CustomerJSON);  // <- Razor (I think) doesn't like this semicolon
    });
</script>

Is this a bug in Razor? If so, is there a way I can rewrite this to avoid this issue?

解决方案

Is this a bug in Razor?

Absolutely not. Run your application, and it will work as expected.

It is a bug in the tools you are using (Visual Studio 2012, ReSharper, ...) that are incapable of recognizing perfectly valid syntax and warning you about something that you shouldn't be warned about. You could try opening an issue on the Microsoft Connect site and signalling this bug if that hasn't already been done.

这篇关于剃刀/ JavaScript和尾随分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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