2013-12-15 1 views
0

부분보기에있는 모달 팝업 제출 버튼에서 jquery 함수를 호출하려고하지만 해당 버튼이있는 경우 함수가 호출되지 않습니다. 부분 뷰에서는 모달 팝업을 메인 뷰에 놓을 때만 호출됩니다. 이 문제를 해결하는 방법 ..... 감사합니다모달 팝업시 모달 팝업 요청시 Jquery 함수가 호출되지 않음 MVC

Index.cshtml 도와주세요

@Html.ActionLink("Create", "Create", null, null, new { id = "btnCreate", @class = "btn btn-small btn-info" }) 
    <script type="text/javascript"> 
     $(function() { 
      $.ajaxSetup({ cache: false }); 
      $('#btnCreate').click(function() { 
       alert("function called"); 
       $('.modal-dialog').load(this.href, function() { 
        $('#ShowModalDialog').modal({ 
         backdrop: 'static', 
         keyboard: true 
        }, 'show'); 
       }); 
       return false; 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $('#Useremail').blur(function() { 
       alert("func called"); 
       $.ajax({ 
        type: 'POST', 
        contentType: "application/json; charset=utf-8", 
        url: 'Home/Search', 
        data: "{'searchString':'" + document.getElementById('Useremail').value + "'}", 
        async: false, 
        success: function (response) { 
         alert("Record found"); 
        }, 
        error: function() { alert("record not found"); } 
       }); 
      }); 
     }); 
    </script> 
    <div id='ShowModalDialog' class='modal fade in'> 
     <div class='modal-dialog'> 
     </div> 
    </div> 
</body> 
</html> 

_Create.cshtml PartialView

당신이 필요로하는 부하 후 폼에 추가 된 항목에 대한
@model MvcTwitterBootstrap.Models.UserDetail 
<div class="modal-content"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> 
      ×</button> 
     <h3 id="myModalLabel"> 
      Registration</h3> 
    </div> 
    @using (Html.BeginForm("Create", "Home", FormMethod.Post, new { @class = "modal-form" })) 
    { 
     @Html.ValidationSummary() 

     <div class="modal-body"> 
      <div> 
       @Html.LabelFor(x => x.UserEmail) 
       @Html.TextBoxFor(x => x.UserEmail, new { @id = "Useremail" }) 
       @Html.ValidationMessageFor(x => x.UserEmail) 
      </div> 
      <div> 
       @Html.LabelFor(x => x.UserPassword) 
       @Html.TextBoxFor(x => x.UserPassword, new { id = "Userpassword" }) 
       @Html.ValidationMessageFor(x => x.UserPassword) 
      </div> 
     </div> 

     <div class="modal-footer"> 
      <button class="btn" data-dismiss="modal" aria-hidden="true"> 
       Cancel</button> 
      <button class="btn btn-primary" type="button" id="btnsubmit"> 
       Save</button> 
     </div> 
    } 
</div> 

답변

0

항목 대신 문서에 기능을 추가하려면

$(document).on('click', '#btnCreate', function(){ 
    //code 
}); 

다른 옵션은 모두 부분이

$('#divContent').html(result); 
LoadScript(); 

를로드 한 후 함수에서 클릭 이벤트의

function LoadScript(){ 
    //jquery code here 
} 

하고 해당 함수를 호출