6

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")'" />
4
  • 1
    Where do you get that error? In the browser, the compiler, or the IDE? Commented May 7, 2013 at 13:53
  • 1
    Is it actually an error? Or just a squiggly line in the IDE? Does it compile and run ok? Commented May 7, 2013 at 14:08
  • just a squiggly red line in the IDE, it runs fine Commented May 8, 2013 at 8:17
  • For me it was just a squiggly line in the IDE view, and technically worked. However the rendered HTML was all messed up at runtime. It looked like 2 buttons sandwiched in some text. I had to use the solution from @vonv. with the concatenation. Commented Jan 31, 2014 at 14:44

2 Answers 2

20

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")  
        + "'")" />
Sign up to request clarification or add additional context in comments.

Comments

12

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.