2012-03-15 5 views
1

내 응용 프로그램에서 MVC3 면도기 뷰와 함께 jquery 모달 팝업을 사용하고 있습니다.MVC3 Razor View PopUps

문제 내가 메뉴 옵션을 클릭하면 팝업을 열어야합니다.이 메뉴 옵션은 Layeout 페이지에 있습니다 (사이트 전체에 표시해야합니다). layeout에 팝업 html 코드가 있어야하므로 모든 페이지 소스에 숨겨진 것으로 나타납니다.

그래서 런타임에만 팝업 html을 만들 수있는 더 좋은 방법이 있습니까?

는 지금이 권리를 사용하여 :

$(id).dialog({ 
      closeOnEscape: true, 
      draggable: true, 
      resizable: false, 
      dialogClass: clz, 
      modal: true, 
      title: $(id + ' .dialog-content').attr('title'), 
      closeText: '' 
     }); 

답변

3

당신은 JQuery UI Dialog plugin을 사용하고 아약스를 통해

예를 모달 대화 상자를로드하는 데 사용할 수 있습니다에 전화를 결합

$('#MyAtag').click(function() { 
// Add a container for the modal dialog, or get the existing one 
var dialog = ($('#ModalDialog').length > 0) ? $('#ModalDialog') : $('<div id="ModalDialog" style="display:hidden"></div>').appendTo('body'); 
// load the data via ajax 
$.get('mycontroller/myaction', {}, 
    function (responseText, textStatus, XMLHttpRequest) { 
     dialog.html(responseText); 
     dialog.dialog({ 
      bgiframe: true, 
      modal: true, 
      width: 940, 
      title: 'My Title' 
     }); 
    } 
); 
}); 

아약스는 링크의 '클릭'이벤트에 '도달'합니다. ajax get 요청은 MVC 프로젝트의 해당 작업에서 부분 뷰를 반환하며, MVC 프로젝트는 모달 대화 상자에 표시됩니다.

public ActionResult MyAction() 
{ 
    // Do Some stuff 
    //... 

    // If the request is an ajax one, return the partial view 
    if (Request.IsAjaxRequest()) 
     return PartialView("PartialViewName"); 

    // Else return the normal view 
    return View(); 
} 

당신이 원하는 무엇인가 : 여기

컨트롤러가 같이 볼 수 있었다 무엇을 거친 예입니다?

+0

괜찮 았어, 고마워, 그래서 만약 내가 '폼'을 팝업에 필요하면 'mycontroller/myaction'에 의해 반환 된 부분보기에서 HTML을 써야하나요? – Aman

+0

예, 내 게시물을 편집하겠습니다. 기다려주십시오. – Razor

+0

어떻게 든 'dialog.html (responseText)'에 응답이 추가되지 않았습니다. 그러면 빈 팝업이 표시됩니다. – Aman

관련 문제