Hi I have an MVC application that use's mvc controller actions to render and post json data to the server. I am having a difficult time extending the umbraco frontend to allow for the Ajax calls.
How can I extend the SurfaceControllers to actually return JSON data?
How do you set up the controller action URLs in umbraco?
We haven't launched, but we are stuck at 4.11.10 at the moment.. Any ideas on a workaround that just uses the umbraco SurfaceController extension class?
[PluginController("DataSearch")] public class DataSearchSurfaceController : Umbraco.Web.Mvc.SurfaceController { private DataFilterHelper dal = new DataFilterHelper(); #region categories drop downs
I have a Controller, which har JsonResult method. I want to call this Json method from controller in my View. but it can not find the umbraco controller method. this works in pure MVC application.
return JSON data from MVC controllers
Trying to Extend Umbraco 4.11.10
Hi I have an MVC application that use's mvc controller actions to render and post json data to the server. I am having a difficult time extending the umbraco frontend to allow for the Ajax calls.
How can I extend the SurfaceControllers to actually return JSON data?
How do you set up the controller action URLs in umbraco?
thanks!
Can you upgrade to Umbraco 6.1 and then you can use the Web API controllers designed for this? See http://our.umbraco.org/documentation/Reference/WebApi/
We haven't launched, but we are stuck at 4.11.10 at the moment.. Any ideas on a workaround that just uses the umbraco SurfaceController extension class?
Hi John
I'm on 6. something, but using the MVC controller to return Json data.
So I'd expect this to work as a method in your surface controller:
It's then routed via: /umbraco/surface/MyController/GetJsonData
Hope that helps
Andy
Thanks for the reply,
[PluginController("DataSearch")]
public class DataSearchSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
private DataFilterHelper dal = new DataFilterHelper();
#region categories drop downs
[HttpGet]
public JsonResult GetCategories()
{
IEnumerable<CategoryModel> categ = dal.FindAllCategories();
return Json(categ, JsonRequestBehavior.AllowGet);
}
#endregion
}
this wasn't routed to /umbraco/surface//GetCategories
thanks!
Just edited my post above - part of the URL I posted got eaten.
You're the best!
umbraco/surface/(controller class name w/o Controller)/GetJsonData gets me that data now
Hi,
I have a Controller, which har JsonResult method. I want to call this Json method from controller in my View. but it can not find the umbraco controller method. this works in pure MVC application.
public class StoreSurfaceController: SurfaceController
{
[HttpPost]
public JsonResult Checkout(ShoppingCartModel model)
{
string message = string.Format("Successfully processed {0} item(s).", model.CartItems.Count.ToString());
return Json(new { Success = true, Message = message });
}
}
Json to call controller from the view
function PostData() {
$.ajax({
url: 'umbraco/surface/Store/Checkout', //this is the umbraco surface path to controller action. problem her!!!!
async: false,
type: "POST",
data: JSON.stringify(m_ShoppingCart),
dataType: "json",
contentType: "application/json; charset=utf-8",
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR + "-" + textStatus + "-" + errorThrown);
},
success: function (data, textStatus, jqXHR) {
$("#Results").show();
$("#ResultMessage").html(data.Message);
}
});
}
thanks in advance...
Try umbraco/surface/StoreSurface/Checkout
is working on a reply...