I have been trying to get a Json data defined based on a string list from the Controller MVC c# for quite some time with no luck. I think I am missing something silly, but can you please guide me here?
I have a controller function returning a view with Viewbag assigned as below :
List<string> Brands;
Brands = GlobalVariables.Brands.Where(m => m.brand_cd != "OOO" && m.brand_cd.Trim().ToLower().Equals(m.main_brand.Trim().ToLower()))
.OrderBy(m => m.brand_cd).Select(m => m.brand_cd.Trim()).Distinct().ToList();
ViewBag.BrandList = Json(Brands);
And In my view I am trying to define a Json varible as
<script>
var brandList = '@ViewBag.BrandList';
</script>
But this isnt helping. I get a string in the result. Any ideas ?
JSONis?'that makes it a string. You may also need to useHtml.Raw-var brandList = @Html.Raw(ViewBag.BrandList);