3

I am a newbie in doing MVC and got stucked in middle someone guide me.

I want to hide div in view based on controller action.

View code:

<div id="mudetails" runat="server" style="width: 99%; padding-top: 4%">
</div>

this is my parent div inside content is present.

Controller code.

public ActionResult Index()
        {  
            // div "mudetails" should not apper
            return View();
        }

 public ActionResult Index(string textbox)
        {
               // div "mudetails" should apper

        }

In pageload the div should not apper but when ActionResult Index(string textbox) action is triggerd the div should appear.. I tried but not able to find correct solution.

3 Answers 3

3

You need to return something in your model to indicate whether or not it should display. At its simplest:

    public ActionResult Index()
    {  
        // div "mudetails" should not apper
        return View(false);
    }

    public ActionResult Index(string textbox)
    {
       // div "mudetails" should apper
       return View(true);
    }

and then in your view:

    @Model bool

    @if (model) {
        <div id="mudetails" runat="server" style="width: 99%; padding-top: 4%">
        </div>
    }
Sign up to request clarification or add additional context in comments.

Comments

2
public ActionResult Index()
  {  
        // div "mudetails" should not apper
        mudetails.Visible = false;
        return View();
    }

public ActionResult Index(string textbox)
    {
           // div "mudetails" should apper
              mudetails.Visible = true;

}

Comments

0

You might want to put something like this in your controller

    public ActionResult Index()
    {  
        ViewBox.ShowDetails = false;
        return View();
    }

    public ActionResult Index(string textbox)
    {
           ViewBox.ShowDetails = true;

    }

Then in your view you can use the following

@if (ViewBox.ShowDetails) {
    <div id="mudetails" runat="server" style="width: 99%; padding-top: 4%">
    </div>
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.