2016-06-13

Razor and Javascript: True != true

This does not work!
$(document).ready(function () {
	if (@ViewBag.isEditMode == true) {
		initialize();
	}
});

I tried to combine MVC ViewBag dynamic boolean property to evaluate and to compare within JavaScript, but found that ViewBag evaluates to value 'True' and that in this context JavaScript compares it with true, which is not the same.

Solution?

var isEditMode = @(ViewBag.isEditMode?"true":"false");
if (isEditMode) {
	initialize();
}

No comments:

Post a Comment