Best approach to to show multiple controls in edit mode RRS feed

  • Question

  • User1052662409 posted

    Hi All,

              This question is not about any issue. It is just to know the best approach regarding the solution.

               I have a view in my application. There are around 150 controls on the page. See the image below for reference.Untitled

    Above  is the only one segment, there are many below.

    When I submit the page it saves all value in database. 

    Now when I want to open it in edit mode, I need to write for every control if the model property have value then show control other wise don't show control.

    if (model.item1!="")


       // change the property of div from display:none to display:block


    By default all controls are display:none;

    I just want to know, is there any other (common) approach which works for all control ?

    If yes, then please suggest.

    Friday, August 30, 2019 6:21 AM


  • User-17257777 posted

    Hi demoninside9,

    You can use Reflection to determine whether to display the property of the model by checking its value like this:

    var properties = Model.GetType().GetProperties();
        foreach(var p in properties)
            if(p.GetValue(Model) != null)
                //change the property of div from display:none to display:block

    Best Regards,

    Jiadong Meng.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2019 9:00 AM