I have a ViewBag.IsLocal set to true in controller. I would like to use jquery to check the ViewBag value and display an alert.
Code:
if(@ViewBag.IsL
Assuming you have set the IsLocal property to a boolean value in your controller action:
public ActionResult Index()
{
ViewBag.IsLocal = true;
return View();
}
you could do this on the view:
And please don't use ViewBag/ViewData. Use view models and strongly typed views.
So here's a better approach that I prefer. You could JSON serialize your view model into a javascript variable and then deal with it. Like this:
@model MyViewModel
Obviously if you don't need your entire view model you could JSON serialize only a subset of it => only the part that will be needed by client scripts.