Reputation: 514
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.
Upvotes: 3
Views: 14342
Reputation: 2875
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;
}
Upvotes: 2
Reputation: 2590
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>
}
Upvotes: 0
Reputation: 7411
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>
}
Upvotes: 3