0

这是必须发生更新的 .cshtml 的一部分:

<script type="text/javascript" src="~/scripts/jquery.unobtrusive-ajax.js"></script>

@using (Ajax.BeginForm("NewMessage",new AjaxOptions { UpdateTargetId = "messages"}))
{

    @Html.TextBox("Enter Message");
    <input type="submit" />

   <div id="messages">      
   </div>     
}

这是行动:

    [HttpPost]
    public ActionResult NewMessage(UserMessage message)
    {
        message.TimePost = DateTime.Now;
        message.Author = "author";
        message.Message = "message";

        return PartialView("NewMessage",message);
    }

为什么我重定向到“NewMessage”操作而不是更新?我应该包括任何其他脚本吗?

4

1 回答 1

2

缺少一些脚本...

<script src="@Url.Content("~/Assets/Js/jquery.min.js")"></script>
<script src="@Url.Content("~/Assets/Js/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Assets/Js/jquery.validate.unobtrusive.min.js")"></script>
<script src="@Url.Content("~/Assets/Js/jquery.unobtrusive-ajax.min.js")"></script>
于 2013-01-23T11:08:36.247 回答