简体   繁体   English

内联JavaScript解析错误中的Razor表达式

[英]Razor expression in Inline javascript parsing error

I am writing in Visual Studio 2012 (Visual Basic) ASP.NET MVC4 project. 我正在用Visual Studio 2012(Visual Basic)ASP.NET MVC4项目编写。

Here is my piece of code: 这是我的代码:

<input type="button" value="EDIT" onclick="MngMCRItem('@Url.Action("EditMCRItem", "MCRForm", Nothing)', {doc_id : '@Model.DOC_ID', item_id : @itm.ITEM_ID_IN_DOC}, this.value)"/>

This code causes the editor show error 此代码导致编辑器显示错误

Unterminated string constant. 无终止的字符串常量。 Expected ')'. 预期为“)”。

Are there any better way to rewrite my code? 有没有更好的方法来重写我的代码? Thank you in advance for every advice. 预先感谢您的每一个建议。

EDIT 编辑
Currently, I have Resharper 8.2.1 with Visual Studio 2013 the problem has gone. 目前,我在使用Visual Studio 2013的Resharper 8.2.1上解决了问题。

You have a problem with double quotes and single quotes here: 您在这里有双引号和单引号的问题:

onclick="MngMCRItem('@Url.Action("EditMCRItem", "MCRForm", Nothing)'

You open double quote here -> "MngMCRItem('@Url.Action(" <- here it's closed so the next part of the command can not be understood... 您在此处打开双引号-> "MngMCRItem('@Url.Action(" <-在这里已关闭,因此命令的下一部分无法理解...

@Alex Art, did you try putting my snippet into the Visual Studio editor and see what is going on? @Alex Art,您是否尝试过将我的代码片段放入Visual Studio编辑器中,看看发生了什么? From that context, I am confident that I did NOT make the mistake. 在这种情况下,我相信我没有犯错。 So, I will provide the clearer snippet below and I think this is easily obvious. 因此,我将在下面提供更清晰的代码段,我认为这很容易理解。

@Code
  Dim testing As String = "Hello World!"
End Code

<script type="text/javascript">
  var test = {
    foo : '@Html.Hidden("helloWorld", testing)', // This is perfectly OK
    bar : 'testing'
  };
</script>

<input type="text" name="inpTesting" value="test" onclick="alert('@testing');" /> <!--ERROR in inline js-->
<input type="text" name="inpTesting" value="" onclick="alert('Hello World!');" /> <!--Server-Compiled(result) Code when using some browser 'view page source'-->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM