4

我想用@ Ajax.ActionLink所以我在CSHTML页面做此弹出一个形式:使用@ Ajax.ActionLink弹出一个形式

@Ajax.ActionLink("click ", "AddToMembers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup" }) 
    <div id="result" style="display:none;"></div> 

,并添加这个脚本:

 <script type="text/javascript"> 
      $(document).ready(function() { 
       $("#result").dialog({ 
        autoOpen: false, 
        title: 'Title', 
        width: 500, 
        height: 'auto', 
        modal: true 
       }); 
      }); 
      function openPopup() { 
       $("#result").dialog("open"); 
      } 
</script> 

在我的控制器中加入此功能:

[HttpGet] 
    public PartialViewResult AddToMembers() 
    { 
     return PartialView(); 
    } 

但是当我点击了“点击”我的形式在新页面在浏览器中打开的。不在我的弹出窗体中 有什么问题?

回答

7

我怀疑你忘了,包括下面的脚本到你的页面:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> 

此脚本用于AJAXify由Ajax.ActionLink帮手产生的锚。还sinde你使用jQuery对话框确保你有引用jQuery UI:

<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script> 
+0

是的,我忘了这个“unobtrusive-ajax.js”对不起 – MHF 2012-02-16 13:01:10