Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show/hide div class based on the variable in the controller

I have a string in the controller which queries Rest API stores the response

string rmID = searchLogic.GetRoomID(rmName.Substring(0, rmName.IndexOf(' '))).Result;

This field is not in the Model class. I need to check if the string rmID is Empty or Null in the Index.cshtml and show/hide a div class

@{
    if (String.IsNullOrEmpty(rmID))
    {
        <div class="row" style="padding-bottom:2rem">

            <div class="col-md-9" style="margin-left:auto;margin-right:auto;text-align:center">
                <b>
                    **You have selected not valid room**
                </b>
            </div>
        </div>
    }
}

But the above one doesnot work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use ViewBag to pass the value of rmID from controller to the View.

string rmID = searchLogic.GetRoomID(rmName.Substring(0, rmName.IndexOf(' '))).Result;

ViewBag.Id = rmID;

Then in the view, Use @ViewBag.Id to receive the value and do judgement.

View

@if (!String.IsNullOrEmpty(@ViewBag.Id))
    {
        <div class="row" style="padding-bottom:2rem">

            <div class="col-md-9" style="margin-left:auto;margin-right:auto;text-align:center">
                <b>
                    **You have selected not valid room**
                </b>
            </div>
        </div>
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading