【问题标题】:Asp.Net MVC Ajax.ActionLink behaivour different when using built in VS2008 dev server to IIS hostedAsp.Net MVC Ajax.ActionLink 在使用内置 VS2008 开发服务器到 IIS 托管时表现不同
【发布时间】:2010-11-17 13:10:03
【问题描述】:

这是一个非常奇怪的问题。我已经开发了一个小型 MVC 应用程序,并且到目前为止使用内置的开发服务器 VS2008 进行了测试,一切都按我的预期工作。我现在已将解决方案移至 IIS 托管,并在使用 Ajax.ActionLink 的视图中看到不同的结果。

actionlink 链接到返回部分视图 (.ascx) 的控制器操作。在链接的 AjaxOptions 中,我指定了 DOM 元素的 UpdateTargetId,我希望操作返回的部分视图被替换。使用内置开发服务器运行应用程序时,行为如预期 -> ajax 调用成功返回部分视图并替换指定的 DOM 元素。但是,当托管在 IIS 中时,控制器操作会成功执行,但结果会呈现在新页面上,而不是替换指定的 DOM 元素。

这里是进行 ajax 调用的页面的相关来源:

<% if (info.CurrentStatus != OrderStatus.Received &&
              info.CurrentStatus != OrderStatus.Processing)
           { %>
                <td><%= Ajax.ActionLink("Reprocess Order", "Reprocess",
                            new { generatedId = info.GeneratedId },
                            new AjaxOptions
                            {
                                UpdateTargetId = "success" + info.GeneratedId,
                                OnSuccess = "reprocessSuccess"
                            })%></td>
        <% } %>

        <td><%= Html.Div("success" + info.GeneratedId) %> </td>

这是提供部分视图的操作:

[RequiresSearch()]
public ActionResult Reprocess(string generatedId)
{
    if (RequestReprocessingOfOrder(generatedId))
    {
        ViewData["reprocessSuccess"] = "Reprocessing request successful. Order is queued for reprocessing";
    }
    else
    {
        ViewData["reprocessSuccess"] = "Reprocessing request failed. Please contact the administrator";
    }

    return PartialView();
}

任何帮助将不胜感激!!!

编辑:我没有很多 mvc/ajax 经验,所以不确定从哪里开始尝试解决这个问题,所以即使是寻找什么的指针也会很棒。

【问题讨论】:

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


    【解决方案1】:

    好的,所以我已经解决了这个问题,原来是由我用于所需视图的脚本的 src 引用引起的(在本例中为 MicrosoftAjax.js 和 MicrosoftMvcAjax.js)。当托管在 IIS 中时,我使用的路径不再有效,因此动态生成路径解决了这个问题。

    替换:

    <script src="/Scripts/MicrosoftAjax.js" type="text/javascript"/>
    <script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"/>
    

    与:

    <script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js")%>" type="text/javascript"/>
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js")%>" type="text/javascript"/>
    

    愚蠢的错误,但考虑到症状,解决方案并不明显。

    【讨论】:

    • 这正是我所需要的。我花了几个小时搞砸这个,直到我在这里看到你的帖子。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2018-03-13
    • 2020-04-06
    • 2018-02-28
    • 1970-01-01
    • 2011-06-06
    相关资源
    最近更新 更多