Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 unterminated string constant syntax error

I have the following code which gives me a syntax error - unterminated string constant.I've matched up the quotes can't seem to spot an issue. Any ideas? It works fine, the syntax error is just annoying.

  <input type="button" class="my-button" value="" name="back" onclick="location.href='@Url.Action(Model.Back.Step.ToString(), "MyController")'" />
like image 634
newbie_86 Avatar asked May 07 '13 13:05

newbie_86


People also ask

How do you fix unterminated string constant?

To solve the "Unterminated string constant" error, make sure to enclose your strings in quotes consistently. String literals must be enclosed in single quotes, double quotes or backticks. When writing a multiline string use backticks.

What does unterminated string mean?

"unterminated string literal" means that somewhere a string variable is opened by not closed properly, either because of un-escaped character in it, or a line break, or something like that.


2 Answers

You can rewrite it like this:

<input type="button" class="my-button" value="" name="back" 
     onclick="@("location.href='" 
        + Url.Action(Model.Back.Step.ToString(), "MyController")  
        + "'")" />
like image 122
von v. Avatar answered Nov 09 '22 15:11

von v.


Use an actionlink instead. This one creates a nice bootstrap button:

@Html.ActionLink("Cancel", "Index", "Home", null, new { @class = "btn btn-default" })
like image 39
Ian Avatar answered Nov 09 '22 16:11

Ian