Asp.net mvc MVC2 Ajax表单不进行不必要的页面刷新

Asp.net mvc MVC2 Ajax表单不进行不必要的页面刷新,asp.net-mvc,ajax,form-submit,Asp.net Mvc,Ajax,Form Submit,我是MVC的新手。我在这里有我的第一个Ajax表单: <div id="test"></div> <div id="MainChatMenu"> <% using (Ajax.BeginForm("SendMessage", "MainChat", new AjaxOptions { UpdateTargetId="test"})) { %> <input id="chatMessageText" type="text" maxleng

我是MVC的新手。我在这里有我的第一个Ajax表单:

<div id="test"></div>
<div id="MainChatMenu">
<% using (Ajax.BeginForm("SendMessage", "MainChat", new AjaxOptions {  UpdateTargetId="test"}))
{ %>
  <input id="chatMessageText" type="text" maxlength="200"  />
<input type="submit" value="Go"/>
<% } %>

确保已包含必要的脚本库:

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


System.Web.Mvc.Ajax.AjaxOptions不包含HttpMode的定义。如果我使用HttpMethod(存在),我会得到与以前相同的行为。你注意到AjaxOptions之前的新{}了吗?不,我没有。现在是:使用(Ajax.beginnform(“SendMessage”、“MainChat”、new{}、new AjaxOptions{UpdateTargetId=“test”、HttpMethod=“POST”}))您的“new{}”必须是routeValue。为什么会有不同?我的操作确实具有HttpVerbs.Post属性值,并且它被执行(断点被命中)。所以“post”似乎还可以。我使用的是MVC2。重载5/11是:actionName、controllerName、ajaxOptions。它也起了作用。很抱歉,你发错了。很抱歉我注意到了这个问题:(哦,很抱歉,这真是个新手问题。包括脚本修复了它!
<% using (Ajax.BeginForm("SendMessage", "MainChat", new{}, new AjaxOptions {  UpdateTargetId="test", HttpMethod="POST"})) %>
<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftAjax.js") %>"></script>
<script type="text/javascript" src="<%= Url.Content("~/scripts/MicrosoftMvcAjax.js") %>"></script>