Mvc: Use String Variables Of A View As Parameter To A Javascript Function Call
How can I call a javascript function within a view(cshtml) and pass some string variables (defined in the view)to be used as parameters for the function call? Say the function java
Solution 1:
You have to distinguish between javascript code and server-side code. Also encode your javascript strings:
@{
string y = "this is a string";
string x = "another";
}
<script type="text/javascript">
functionjavascriptFunction(first,second)
{
alert(first+' '+second);
}
javascriptFunction(@Html.Raw(Json.Encode(y)), @Html.Raw(Json.Encode(x)));
</script>
Post a Comment for "Mvc: Use String Variables Of A View As Parameter To A Javascript Function Call"