How to assign JavaScript value under MVC3

How to assign JavaScript value under MVC3 Razor?

I am not sure if it will work...

Thank you!

<script type="text/javascript">

      var populate = false; // This is JS variable

       @if (Session["TechList"] == null)
       {
            populate = true;
       }

</script>

Answers:

Answer
var populate =false;
@if (Session["TechList"] == null)
{
    @:populate = true;
}

This will also work

@if (Session["TechList"] == null)
{
  <text>populate = true;</text>
}

But i like to use the first one as it is more clean

Answer

My suggestion:

<script type="text/javascript">
     var populate = @(Session["TechList"] == null ? "false": "true");
</script>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.