This has been asked before in a previous unsolved thread from 2013, so I wonder if best practice has been figured out since then, or if
any new comers could help me out.
I am implementing my existing MVC project into Umbraco. In my existing project I have async ajax posts to my controllers using jQuery. Using Umbraco SurfaceController, the task will look like this:
public class MySurfaceController: SurfaceController
{
[HttpPost]
public JsonResult PostThatReturnsJSon(myModel model)
{
// Some logic here that involves
// HttpContext.Current.Session["SomeSessionVariable"];
string message = string.Format("Successfully processed");
return Json(new { Success = true, Message = message });
}
}
This will not work, and by reading articles about Umbraco Surface Controllers, it is stated that Surface Controllers are only designed for "normal" form posts and for returning i.e. "CurrentUmbracoPage".
Then there is the UmbracoApiController, but since an ApiController is stateless, it is not possible to use logic that involves sessions or cookies.
I would be thankful if someone has figured out the solution for this – or a hint to a solution :-)
Async post to controller that returns JSon
Hi
This has been asked before in a previous unsolved thread from 2013, so I wonder if best practice has been figured out since then, or if any new comers could help me out.
I am implementing my existing MVC project into Umbraco. In my existing project I have async ajax posts to my controllers using jQuery. Using Umbraco SurfaceController, the task will look like this:
This will not work, and by reading articles about Umbraco Surface Controllers, it is stated that Surface Controllers are only designed for "normal" form posts and for returning i.e. "CurrentUmbracoPage".
Then there is the UmbracoApiController, but since an ApiController is stateless, it is not possible to use logic that involves sessions or cookies.
I would be thankful if someone has figured out the solution for this – or a hint to a solution :-)
Best regards
For sure you can use SurfaceController for an ajax POST?!
You just need to post to
/umbraco/surface/MySurface/PostThatReturnsJSon
.Thank you Tobias, I was missing the "/umbraco/" part of the path... :-O
Thx.
is working on a reply...