@myVariable
is a server-side variable it get's it's value from server before rendering the page
@myVariable
will print the value of the variable not assign to it,
so the output of @myVariable = true;
will be
false = true;
use ajax to get content from server
@{
bool myVariable = false;
}
<script type="text/javascript">
function Foo() {
if (some_condition)
{
$('#newContent').load('/News/GetLatest/10'); // call ajax to get content
}
}
</script>
<div id="newContent">
<!-- stuff -->
</div>
or you can only show the div if condition is true on the client side
@{
bool myVariable = false;
}
<script type="text/javascript">
var showContent = @myVariable; // false
function Foo() {
if (some_condition)
{
showContent = true;
$('#newContent').show(); // show it
}
}
</script>
<div id="newContent" style="display: none;"> <!-- hidden by default -->
<!-- stuff -->
</div>