ajax.actionlink(){}正在重新加载页面而不是调用ajax

时间:2014-08-14 17:50:10

标签: javascript jquery ajax asp.net-mvc

我正在尝试调用ajax操作而不是重新加载页面但是似乎在这里工作的东西是我实现ajax.action方法的索引

@model IEnumerable<MessagingProject.Models.chating>  
@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
    @Ajax.ActionLink("Info", "info","Chat", new AjaxOptions
       {
           UpdateTargetId = "AliHamadi",
           InsertionMode = InsertionMode.Replace,
           HttpMethod = "get"
       })
    @Html.ActionLink("Create New", "Create")
</p>
<table >
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.sending)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.reciving)
        </th>
        <th></th>
    </tr>  
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.sending)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.reciving)
        </td>
        <td>

            @Html.ActionLink("Info", "info", new {ID=item.id }) |

            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
    </tr>
}   
</table>
<div id="AliHamadi">
</div>

这是我的行动信息行动方法

public PartialViewResult info()
            {
                var model = messageContext.messages.Select(r => r.name == "ali").Single();
                return PartialView("info",model);
            }

这是我的布局视图,我实现了我的jquery脚本

<!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title</title>
        <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />


    </head>
    <body>
        <ul id="menu">
            <li>@Html.ActionLink("Home", "Index", "Home")</li>
            <li>@Html.ActionLink("Chatting", "Index", "Chat")</li>
            <li>@Html.ActionLink("About", "About", "Home")</li>
        </ul>
        <section id="main">
            @RenderBody()
            <p>Copyright W3schools 2012. All Rights Reserved.</p>
        </section>
           @* @Content.Script("jquery-2.1.1.min.js", Url) *@
        <script src="~/Scripts/jquery-2.1.1.js"></script>
        <script src="~/Scripts/jquery-2.1.1.min.js"></script>
    </body>     
</html>

我重新加载整个页面,而不是调用info方法并在索引视图中实现它

1 个答案:

答案 0 :(得分:2)

是的斯蒂芬我实际上忘了在我的项目中加入unobtrusive.js。 谢谢你提及它。

亲切的问候。