2013-07-11 2 views
3

MVC를 수행하는 초보자이며 중간에 갇혔다가 나를 인도합니다.MVC 2에서 C#을 사용하여 Div를 표시하고 숨기는 방법 aspx

나는 컨트롤러 동작에 따라보기에서 div을 숨기려고합니다.

보기 코드 :

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

이 콘텐츠 안에 내 부모 사업부가 존재한다.

컨트롤러 코드.

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

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

     } 

pageload에서 div는 apper 안하지만 ActionResult Index(string textbox) 조치가 triggerd 때 div 내가 시도했지만 올바른 해결책을 찾을 수 없습니다 ... 나타납니다.

답변

2

모델을 표시할지 여부를 나타내려면 모델에서 반환해야합니다. 간단한에서 :

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

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

다음보기 :

@Model bool 

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

당신은 당신이 사용할 수 있습니다보기에

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

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

    } 

그런 다음 컨트롤러 같은 것을 넣어 할 수 있습니다 다음

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

} 
관련 문제