Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ajax.action链接未显示成功警报_Asp.net Mvc_Asp.net Ajax - Fatal编程技术网

Asp.net mvc ajax.action链接未显示成功警报

Asp.net mvc ajax.action链接未显示成功警报,asp.net-mvc,asp.net-ajax,Asp.net Mvc,Asp.net Ajax,我正在开发asp.NETMVC2应用程序。我有ajax.action链接,但它不起作用。我认为有以下代码: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

我正在开发asp.NETMVC2应用程序。我有ajax.action链接,但它不起作用。我认为有以下代码:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   <script type="text/javascript">
       function success(result) {
           alert(result);
           // TODO: do something with the object
       }
   </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%: Ajax.ActionLink(
    "Delete", 
    "Delete", 
    new { Id = 55 }, 
    new AjaxOptions { OnComplete = "success" })
%>
</asp:Content>

但当我点击链接,它显示记录删除!在浏览器中,而不是显示为警报。我是否缺少一些文件?

您可能需要在页面中包含
MicrosoftJax.js
MicrosoftMvcAjax.js
脚本:

<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftAjax.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftMvcAjax.js") %>"></script>
您可以在视图中覆盖的:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Scripts" runat="server">
    <script type="text/javascript">
        function success() {
           alert('success');
           // TODO: do something with the object
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%= Ajax.ActionLink(
        "Delete", 
        "Delete", 
        new { id = 55 }, 
        new AjaxOptions { OnComplete = "success" }
    ) %>
</asp:Content>

函数成功(){
警惕(“成功”);
//TODO:对对象执行某些操作
}

stackoverflow.com/questions/15448070/ajax actionlink未显示成功警报@添加了此问题,但仍然是相同的问题您确定这是ASP.NET MVC 2应用程序而不是ASP.NET MVC 3吗?另外,请查看您的浏览器控制台,看看是否存在一些js错误。是的,我正在使用asp.net MVC 2控制台中是否存在任何错误?还有,您在哪里包含了这些脚本?是的,我在控制台中包含了脚本,没有错误。当我点击链接时,会出现一个错误,但消失得太快,以至于我无法注意到它,然后显示ajax。
<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftAjax.js") %>"></script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftMvcAjax.js") %>"></script>
    <asp:ContentPlaceHolder ID="Scripts" runat="server" />
</head>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Scripts" runat="server">
    <script type="text/javascript">
        function success() {
           alert('success');
           // TODO: do something with the object
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%= Ajax.ActionLink(
        "Delete", 
        "Delete", 
        new { id = 55 }, 
        new AjaxOptions { OnComplete = "success" }
    ) %>
</asp:Content>