0

I have the following div in my view:

<div id="review">
    REVIEW:
  <p>
    <%:ViewData["Review"]%>
  </p>   
    <input name="submit" id="submit" type="submit" value="OK"/>
</div>

How can I set DIV visibility to visible inside of controller when a certain button is clicked?

This is a code fragment in my controller:

public ActionResult Index(EsafeModel model,string submit, string create)
{
   if (button.Equals("Create"))
   {
      ViewData["Review"] = ESafeData.CreateReview(eSafe);
   }
   else if (button.Equals("OK"))
   {
      if (ESafeData.Create(eSafe))
      {
         ViewData["Message"] = "E-Safe data created!!!";
      }
   }
}
tereško
  • 58,060
  • 25
  • 98
  • 150
gene
  • 2,098
  • 7
  • 40
  • 98

1 Answers1

0

You can't do this directly as div is on client side and the controller is server side. What you can do is have a property in your model which is bound to view .This can have the value of visibility attribute for div and then you can assign it using server tags to div

Below is a sample code snippet

 <div id="elementid" style="visibility:'<%=Model.Visible %>'"/>

On the click of button you can return the same view and model but this time model will have Visible ="hidden"

Jags
  • 772
  • 7
  • 17
  • I have MVC2. Does it make a difference how to access a model? When I use this approach I'm getting an error saying object reference is null – gene Oct 30 '14 at 19:36
  • You need the entire code? I already submitted the fragments of controller and view? I think my problem is that when I first call the view, its model's `visibility` property is not set. I need to set it somewhere to `hidden` before accessing the view for the first time – gene Oct 30 '14 at 20:01