Mediator
Mediator

Reputation: 15378

The syntax to use in the input

I have error in ='@

unterminated string constant

<input class="blue" type="button" onclick="location.href='@(Url.Action("Index", "Home", Model.RouteData))';" value="Index"/>

how to solve this?

Upvotes: 2

Views: 504

Answers (2)

mkey
mkey

Reputation: 535

<input class="blue" type="button" onclick="location.href='@(Url.Action(\"Index\", \"Home\", Model.RouteData))';" value="Index"/>

This should work. But you should really limit the usage of inline CSS/JS.

Something like this should be better.

HTML

<input id="button" class="blue" type="button" value="Index"/>

JS

document.getElementById("button").onclick= function(){
   location.href='@(Url.Action("Index", "Home", Model.RouteData))';
}

Upvotes: 2

Microsoft DN
Microsoft DN

Reputation: 10020

String constants must be enclosed within a pair of quotation marks.

Try this-

<input class="blue" type="button" onclick="location.href='@(Url.Action('"Index"', '"Home"', Model.RouteData))';" value="Index"/>

Upvotes: 0

Related Questions