Monday, May 20, 2024
65
rated 0 times [  69] [ 4]  / answers: 1 / hits: 48469  / 14 Years ago, fri, march 4, 2011, 12:00:00

how would I do the equivalent of this embedded in JavaScript on an MVC2 aspx page:



if (('<%= Model.SomeFunctionEnabled %>' == 'True') and also a whole function code block on a Razor view page (cshtml) in MVC3?



Something like :



@{
foreach(var d in Model.Employees)
{
....
}
}


Which works fine when embedded in the HTML part of the view page.
Thanks


More From » asp.net-mvc-3

 Answers
18

Why testing on the client side when you could do this on the server side and include the javascript to act accordingly if the test succeeds:



<script type=text/javascript>
@if (Model.SomeFunctionEnabled) {
<text>
// Put your javascript code here
alert('the function is enabled');
</text>
}
</script>

[#93434] Thursday, March 3, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josuea

Total Points: 609
Total Questions: 121
Total Answers: 104

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
josuea questions
;