【问题标题】:asp.net mvc Ajax.ActionLink problemasp.net mvc Ajax.ActionLink问题
【发布时间】:2013-02-26 04:07:17
【问题描述】:

我做错了,我不知道在哪里......

我认为这是 - 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...我做错了什么?

附言

在 MicrosoftMvcAjax.debug.js 中使用 vs.net 进行调试时出现错误

在 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

【问题讨论】:

    标签: asp.net-mvc asp.net-ajax


    【解决方案1】:

    我已经找到了我的问题...似乎我使用的 MicrosoftMvcAjax.js 的版本不是最新的...。 如果您遇到与我获得最新版本的 mvccontrib 类似的问题...

    【讨论】:

      【解决方案2】:

      您是否记得在调用 AjaxLink 之前包含必要的 javascript 文件?

      您需要参考 MicrosoftAjax.js 和 MicrosoftMvcAjax.js 才能正常工作。

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-09-16
          • 1970-01-01
          • 1970-01-01
          • 2012-02-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多