MVC2 Ajax Form does unwanted page refresh
Posted
by Kay
on Stack Overflow
See other posts from Stack Overflow
or by Kay
Published on 2010-06-16T19:45:02Z
Indexed on
2010/06/17
7:13 UTC
Read the original article
Hit count: 824
Hi,
I am pretty new to MVC. I have my first Ajax Form here:
<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"/>
<% } %>
Now, if I click the submit button, the page is reloading, goint to mysite/controller/action. I thought that the default behaviour of the Ajax.BeginForm was exactly not to do that? Where's my newbie mistake?
My Controller is called correctly, but data passing also doesn't work. Probably because of the same mistake? Here's the code:
public class MainChatController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public EmptyResult SendMessage(FormCollection formValues)
{
return new EmptyResult();
}
}
© Stack Overflow or respective owner