Umbraco 5 Implements Ajax By Adding New MVC Scope
I am trying to implement AJax on Umbraco 5 (jupiter), I tried to create Surface controllers that works fine with regular mail, but does not provide the ability to use Mjc Ajax Controls, i.e. Ajax.BeginForm Etc ... I added a new MVC scope to my application, I can easily send a "Back via Ajax Form" message to the Action Controller, but I have to go back to this action as CurrentUmbracoPage is not available (since it is not a Surface Controller). my code is pretty simple,
@using (Ajax.BeginForm("HandleFollowsUs", "propertyDetails", new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "POST", LoadingElementId = "ajax-loader", UpdateTargetId = "fuError" }))
{
<input type="image" style="border-width: 0px;" src="/images/btnSubmitN.jpg" id="btn_submitEmail" /></span>
}
AND my ACTION is
[HttpPost]
public ActionResult HandleFollowsUs(FormCollection collection) {
//Do Something
Return View();//////This is where i am confused.
}
If I return View, it is not in the New area, the partial view will only return a small portion of the page: // Any help would be appreciated, Thanks, Sher
source to share
Use Jquery Ajax instead and return a string, this will not result in normal Umbraco 5 routing. Sample code below
function loadList(){
$.ajax({
type: "POST",
url: "/en/propertydetails/searchListView",
data: "loc=" + loc + "&startDate=" + startDate + "&endDate=" + endDate + "&bedrooms=" + bedrooms + "&adults=" + adults + "&children=" + children + "&offerCode=" + offerCode,
error: function (xhr, status, error) {
//alert('error');
},
success: function (response) {
//do something with response
populateSearchList(response);
}
});
}
And my action
[HttpPost]
public string searchListView(string loc, string endDate, string startDate, string bedrooms, string adults, string children, string offerCode)
{
//Do Something
}
source to share
If you submit the current url as hidden form files, you can redirect the HandleFollowUs cursor.
But if I understand correctly, you just want to do some client side validation? Consider using the unobtrusive validation framework already present in the MVC framework. Take a look at this post for more info: ASP.NET MVC 3 - Ajax.BeginForm vs jQuery Form Plugin
source to share