-1

We have stored the controls information(id, name etc.) in our database.

Now, based on the data we want to show/hide controls using jQuery in MVC.

What we are thinking is store controls information in key(ControlName) / value(Show/hide) pair in json format

and pass this json to jQuery function and in function based on value controls will be shown/hidden.

So, how can I do it ?

David
  • 45
  • 7
  • 1
    are you using Ajax to load the page? because if you are not, no need to supply the data as JSON. a better way would be to create a ViewModel for your page, and inside this viewmodel, specify the required information which you will deal with inside the view in order to show/hide the controls. – Mohammed Swillam Oct 21 '14 at 11:56
  • No I am not using Ajax to load the pages. Can you please explain in detail ? – David Oct 21 '14 at 12:11

1 Answers1

0

continuing from my above comment, what you gonna need is to create a ViewModel which will hold all the information required by your view, then using a simple for (or foreach) loop, you will display the ones you should display. if you are not familiar with Viewmodel technique, please check the following links:

the Viewmodel will contain the list (or as per you suggestion, a dictionary) which conatins the items with it's proper flag that indicates wheather this item should be displayed or not, then inside your view, you will iterate over this list and render the items which should be displayed

example:

foreach(var item in Model.myItemsList)
{
   if(item.IsVisible==true) // or check your custom property here
   {
      // render your item here
   }
}
Community
  • 1
  • 1
Mohammed Swillam
  • 9,119
  • 4
  • 36
  • 47