Hi I've just created a a new Umbraco 7.5.3 site. Last time I worked in Umbraco was on version 4.x-something.
I'm wondering how you use the Ajax.BeginForm to do a "async" post back to my controller. When I wire it up it does a full postback.
I see that I can set OnComplete methods on the AjaxOptions and I tried those as well but I simplified the example below.
It seems that I should include some external javascript to make it work?
Note: I have build my own javascript submit hijacker. But I'm still curious how to get the out-of.box experience
Test.cshtml
@using (Ajax.BeginForm("SendMail", "Contact", new AjaxOptions { HttpMethod = "POST" })) {
<fieldset>
<legend>Send me to the SurfaceController </legend>
<input type = "submit" value="Send Message">
</fieldset> }
Controller
public class ContactController : SurfaceController
{
[HttpPost]
public JsonNetResult SendMail()
{
var result = new JsonNetResult
{
Data = "Hello from controller"
};
return result;
}
}
Ajax POST to Surface Controller in Umbraco 7.5.3
Hi I've just created a a new Umbraco 7.5.3 site. Last time I worked in Umbraco was on version 4.x-something.
I'm wondering how you use the Ajax.BeginForm to do a "async" post back to my controller. When I wire it up it does a full postback.
I see that I can set OnComplete methods on the AjaxOptions and I tried those as well but I simplified the example below.
It seems that I should include some external javascript to make it work?
Note: I have build my own javascript submit hijacker. But I'm still curious how to get the out-of.box experience
Test.cshtml
Controller
Thanks in advance, Olle
Hi Olle.
Few thing you should check that could be causing the problem.
First: Do you have all the required scripts referenced? You need the following (besides jquery):
Second: In your web.config, you need to allow UnobtrusiveJavascript. Add the following in your appKeys:
Here are my code example based on your code, and it works fine when i have the appKey in my web.config and the exact same Controller as you:
Output:
Hope this was helpful!
Take care!
I was missing the jquery.unobtrusive-ajax.min.js lib.
It's now working as expected.
Thanks for taking your time with such complete answer.
Kind regards, Olle
Thank you, Im glad it worked out Olle!
Have a great day!
is working on a reply...