Reputation: 872
I want split Javascript code by newlines, but the compiler gives me an error:
<%= Html.ActionLink("Delete", "delete", new { id = Model.Id },
new {
@class="button-link",
onclick = " javascript;
javascript goes here;
javascript goes here;
javascript goes here;
return false;"
}
); %>
Upvotes: 0
Views: 912
Reputation: 269628
You could use a verbatim string literal -- starting the string with the @
symbol -- but it probably makes more sense to move your JavaScript out into a separate .js
file, as Darin suggests.
<%= Html.ActionLink("Delete", "delete", new { id = Model.Id },
new {
@class = "button-link",
onclick = @"javascript;
javascript goes here;
javascript goes here;
javascript goes here;
return false;"
});
%>
Upvotes: 2
Reputation: 1039438
Not directly answering your question but proposing an alternative: javascript has nothing to do in HTML and both should never be mixed. It should be in a separate file:
<%= Html.ActionLink(
"Delete", "delete", new { id = Model.Id },
new { @class = "button-link", id = "foo" }); %>
and then in a separate js file (using jquery):
$(function() {
$('#foo').click(function() {
// TODO: put as many lines of javascript as you wish here
return false;
});
});
This way your markup is smaller, static resources such as javascript is cached by the client browser and you don't need to worry about simple, double, triple quotes, ...
Upvotes: 1