2014-05-15 3 views
1

2 개의 (약간 다른) 링크가있는 간단한 예제보기가 있습니다. 하나는 인라인 확인이고 다른 하나는 JQuery를 사용하여 대화 상자를 표시합니다. 그들은 모두 같은 장소에서 끝나야하고 컨트롤러 이벤트를 제대로 수행하는 것으로 보입니다. 인라인 액션은 잘 작동하며 긍정적 인 응답으로 결과 페이지로 리디렉션합니다. jQuery/JavaScipt 이벤트도 컨트롤러를 쳐서 결과 페이지의 렌더링으로 추적했지만 실제로는 아무것도 렌더링하지 않습니다.ASP.net jQuery 대화 상자가 완료되지 않음

이제 내가 조금 이상한 일은 결과 액션에 URL을 저장하는 숨겨진 필드이지만, URL을 부적절하게 사용하여 문제를 피하기 위해 올바른 방식으로 저장하는 것 같습니다. JavaScript로 읽으십시오.

Dialog.cshtml :

@using System.Globalization 
@{ 
    ViewBag.Title = "Dialog"; 
} 

<link href="~/Content/bootstrap-theme.css" rel="stylesheet" /> 
<link href="~/Content/bootstrap.css" rel="stylesheet" /> 
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" /> 
<script src="~/Scripts/jquery-2.1.0.js"></script> 
<script src="~/Scripts/jquery-ui-1.10.4.js"></script> 
<script src="~/Scripts/bootstrap.js"></script> 

<h2>Dialog</h2> 

<p><a href='@Url.Action("Result")' onclick="return confirm('Are you really sure?');">Click Me</a></p> 

<button type="button" id="TestLink">Show JQuery Dialog</button> 

<input type="hidden" id="RouteUrl" value='@Url.Action("Result")' /> 

<div id="dialog" title="jQuery UI in ASP.NET MVC"> 
    <p>You now have the power of ASP.NET, the simplicity of client-side scripting with jQuery, and the looks of jQuery UI. Congrats, web slinger!</p> 
</div> 

<script type="text/javascript"> 
    // This code runs on page load 
    $(function() { 

     // Attach a 'dialog' action to the dialog div above 
     $('#dialog').dialog({ 
      autoOpen: false, 
      modal: true, 
      width: 450, 
      buttons: { 
       "Ok": function() { 
        $(this).dialog("close"); 
        var url = $("#RouteUrl").attr("value"); 
        $.get(url); 

        return true; 
       }, 
       "Cancel": function() { 
        $(this).dialog("close"); 
        return false; 
       } 
      } 
     }); 

     // Show the dialog when the show-dialog click event fires 
     $("#TestLink").button().click(function (e) { 
      $('#dialog').dialog('open'); 
      e.preventDefault(); 
     }); 
    }); 
</script> 

및 컨트롤러는

using System.Web.Mvc; 

namespace MVCWorkbench.Controllers 
{ 
    public class JavaScriptController : Controller 
    { 
     public ActionResult Dialog() 
     { 
      return View(); 
     } 

     public ActionResult Result() 
     { 
      return View(); 
     }  
    } 
} 

답변

0

내가 제대로 이해한다면 확실하지 않다. 대화 상자에서 [확인] 단추를 클릭하거나 대화 상자 ActionResult에서 데이터를로드하여 대화 상자에 배치하려고 할 때 url을 탐색하려고합니까?

코드에 따라 대화 상자에서 확인을 누른 후 페이지를 탐색하는 것처럼 보입니다. 그 대신

$.get(url); 

사용을 사용, 그렇다면 :

window.location.href(url); 

jQuery를 서버에서 데이터를 검색하는하지만 당신은 현재 그것으로 아무것도하지 않습니다.

+0

Humm, IE에서 일관되게 작동하지만 Chrome에서 오류가 발생합니다. Uncaught TypeError : string이 함수가 아닙니다. (줄 38) $ (this) .dialog ("close "); .... ??? 그 오류는 내가 실종되었다는 것을 나타내는 것 같다. ? – cantis

관련 문제