MVC3未结束的字符串常量语法错误(MVC3 unterminated string constan

2019-09-02 03:44发布

我有以下的代码,给了我一个语法错误 - 匹配了报价似乎无法发现的问题未终止的字符串constant.I've。 有任何想法吗? 它工作正常,语法错误仅仅是烦人。

  <input type="button" class="my-button" value="" name="back" onclick="location.href='@Url.Action(Model.Back.Step.ToString(), "MyController")'" />

Answer 1:

你可以把它改写如下:

<input type="button" class="my-button" value="" name="back" 
     onclick="@("location.href='" 
        + Url.Action(Model.Back.Step.ToString(), "MyController")  
        + "'")" />


Answer 2:

使用ActionLink的来代替。 这一次创建了一个很好的引导按钮:

@Html.ActionLink("Cancel", "Index", "Home", null, new { @class = "btn btn-default" })


文章来源: MVC3 unterminated string constant syntax error