I need help using viewbag value to hide a column in my Kendo UI grid

Hi Experts,
I have an MVC.Net application with C#.Net code behind.
I want to use a Viewbag value to determine if some columns in my Kendo UI grid should be hidden or not.

below is a snippet of the code I was trying to use, but it does not work.
How can I make this work?

columns: [
@if(ViewBag.AllowEdit)
{
        {   
             field: "IPA",
             title: "IPA",
         },
        {
             field: "TEST",
             title: "TEST",
        },
}

Open in new window



Thanks in advance,
mrotor
mainrotorAsked:
Who is Participating?
 
louisfrCommented:
When using Razor Inside javascript, you have to clearly mark where things start and end.
Use <text> around the javascript code:
columns: [
@if(ViewBag.AllowEdit)
{
        <text>
        {   
             field: "IPA",
             title: "IPA",
         },
        {
             field: "TEST",
             title: "TEST",
        },
        </text>
}

Open in new window

1
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Assuming that you have set ViewData[“AllowEdit”] = true; in the controller method that returns the View, this should work. Please explain what makes you say it doesn’t work?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.