2009-10-01 54 views
0

我做错了什么,我无法揣摩出...asp.net的MVC Ajax.ActionLink问题

我有这个在我看来 - CreateForm.aspx

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %> 

     <%= this.Ajax.ActionLink("Create New", "CreateForm", new { nr=ViewData["Nr"]??0 }, new AjaxOptions { UpdateTargetId = "panel" + (String.IsNullOrEmpty((string)ViewData["Nr"]) ? "0" : "1") }, new { id = "panel" + (String.IsNullOrEmpty((string)ViewData["Nr"]) ? "0" : "1") + "Form" })%> 

    <div id="panel<%=String.IsNullOrEmpty((string)ViewData["Nr"])?"0":"1"%>"></div> 

我有这个在我的控制器 -

 public ActionResult CreateForm(int nr) 
     { 
      ViewData["Nr"] = (nr++).ToString(); 
      return PartialView(); 
     } 

当我点击我想到的是响应我的面板#加载(panel0,PANEL1 ...),但我重定向到一个空白页,只有返回的内容链接

这是生成的html

<a href="/Member.aspx/CreateForm?nr=0" id="panel0Form" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'panel0' });">Create New</a> 

    <div id="panel0"></div> 

,并点击页面查看源代码看起来像这样

<a href="/Member.aspx/CreateForm?nr=0" id="panel1Form" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'panel1' });">Create New</a> 

    <div id="panel1"></div> 

我已经包含了以后的Ajax JS

<script src="/content/Microsoft/MicrosoftMvcAjax.debug.js" type="text/javascript"></script> 

,但我预计这将进入panel0 ...我做错了什么?

P.S.

与vs.net调试运行在MicrosoftMvcAjax.debug.js我得到一个错误

周围线3063 ...

var e = Function._validateParams(arguments, [ 
     {name: "id", type: String}, 
     {name: "element", mayBeNull: true, domElement: true, optional: true} 
    ]); 
    if (e) throw e; <-here it trows an error 

回答

1

我已经想通了我的问题......它接缝,我正在使用的MicrosoftMvcAjax.js版本不是最新的.... 如果您有类似的问题,因为我有最新版本的mvccontrib .. 。

0

你记得打电话AjaxLink之前,包括必要的JavaScript文件?

您需要引用MicrosoftAjax.js和MicrosoftMvcAjax.js才能正常工作。

+0

是的,我把它们包括在我的Site.Master – bogdanbrudiu 2009-10-01 20:50:55

0

我对这类问题有一些经验。看起来我们必须以正确的顺序使用脚本文件来使其工作。更具体地说,您应该在MicrosoftMvcAjax脚本之前包含MicrosoftAjax。 希望它有帮助