2014-11-24 5 views

답변

3

에 대한

[HttpPost] 
     public ActionResult Index(int contractType) 
     { 
      if (contractType == 0) 
      { 
       return "SHOW MODALDIALOG BOX" with button "YES" and "NO" when click "YES" Refirect to nexe page, click "NO" stay in current page 
      } 
      else 
      { 
       return View(); 
      } 
     } 

덕분에 당신은 팝업을 표시 할 수 없습니다. VIEW에서 javascript 모달 대화 상자를 표시 할 수 있도록 플래그를 사용하여 뷰를 반환 할 수 있습니다.

다른 옵션은 뷰 대신 JSON을 반환하고 JS를 사용하여 모달 대화 상자를 만듭니다. ... 예 clic 예, 당신은 다른 매개 변수 (귀하의 경우 다른 '0')와 동일한 컨트롤러 작업을 호출 할 수 있으며 이번에는보기를 표시합니다.

예 :보기에

[HttpPost] public ActionResult Registering() { string RetResult = new UserPermission().ValidateUser(Request["username"].ToString(), Request["password"].ToString()); if (!string.IsNullOrEmpty(RetResult)){ ViewBag.MyErrorMessage = RetResult; return View(); //This will show the view named "Registering", but you can display any other. //The ideal is display the same one where the user entered the user/pass. } else { return RedirectToAction("Index", "EvalMain"); } } 

:

@if(ViewBag.MyErrorMessage != null){ 
    //Display the error message 
    //You can: display it in a div (without popup), you can show a javascript Alert(), or display a modal dialog.  
} 

은 DIV로 표시하려면 단순히 수행

<div>@ViewBag.MyErrorMessage </div> 

)은 (경고를 표시하려면 다음

<script> alert(@ViewBag.MyErrorMessage);</script> 

는 모달 대화 표시하려면, 당신은 jQueryUI 사용할 수 있습니다 :이 같은 http://jqueryui.com/dialog/ 더 많거나 적은 무엇인가 : 답변

<div id="dialog" title="Error Registering"> 
<p>@ViewBag.MyErrorMessage</p> 
</div> 

<script> 
    $(function() { 
    $("#dialog").dialog(); 
    }); 
</script> 
+0

몇 가지 예를 보여주십시오. – PaataPP

+0

좋아요,하지만 당신이 성취하려고하는 논리에 대해 좀 더 말해주세요 ... 모달 대화 상자의 아이디어는 무엇입니까? 보기에 무엇을 표시하고 있습니까? – Romias

+0

답변 해 주셔서 감사합니다. 아이디어는 매우 샘플입니다. 나는 eMemberShip WCF 서비스를 운영하고 있는데, ussername과 password를 받아들이고 사용자 역할과 권한을 돌려 준다. 사용자 이름이나 암호가 올바르지 않으면 서비스가 Error string을 반환하고이 오류 문자열과 함께 ModalDialog를 표시하고 다른 페이지로 리디렉션하지 말아야합니다. – PaataPP

0

감사합니다 . 아이디어는 매우 간단합니다. 나는 eMemberShip WCF 서비스를 운영하고 있는데, ussername과 password를 받아들이고 사용자 역할과 권한을 반환합니다. 사용자 이름이나 암호가 올바르지 않으면 서비스가 Error string을 반환하고이 오류 문자열과 함께 ModalDialog를 표시하고 그렇지 않은 경우 다른 페이지로 리디렉션합니다.

[HttpPost] 
    public ActionResult Registering() 
    { 

     string RetResult = new UserPermission().ValidateUser(Request["username"].ToString(), Request["password"].ToString()); 



     if (!string.IsNullOrEmpty(RetResult)) 
      return this.ModalDialog(RetResult); 

     else 
      return RedirectToAction("Index", "EvalMain"); 
    }