2013-12-15 17 views
0

我想調用模態彈出式提交按鈕,這是在部分視圖上的jquery函數,但如果該按鈕是在部分視圖中,只有當我將我的模態彈出到主視圖中時纔會調用它。如何解決這個問題...請幫助..謝謝JQuery的函數調用時調用模態彈出在ASP.net中的部分視圖中的提交按鈕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 
}); 

另一種選擇是將所有在功能的單擊事件的

function LoadScript(){ 
    //jquery code here 
} 

,然後調用該函數的部分加載

$('#divContent').html(result); 
LoadScript(); 
相關問題