This project is read-only.

returning json result from ajax form post with anti forgery disabled.

Topics: Writing modules
Aug 13, 2012 at 10:12 PM
Edited Aug 14, 2012 at 10:24 AM
I am using ajax to submit a form to controller action.  The controller action is called correctly , but although response is json it does  not get passed to the success parameter of the ajax call. Rather i get a screen with the json result printed on it and the url gets set to the {area}/{controller}/{action} value. antiforgery has been disabled in module.txt 
while debugging it looks like after the controller action is complete then control is handled to the UnhandledExceptionFilter class by orchard. But examining the context there is no exception beeing passed in.

view code 
@using (Html.BeginForm("SaveGeneralSettings" ,"WidgetStyler" , FormMethod.Post,  new {id = "frmwidgetGeneralSettings" }))
        <input type="hidden" id="widgetid" name="widgetid" value="@ViewBag.widgetid"/>
                @Html.LabelFor(model => model.BackColor)
                @Html.TextBoxFor(model => model.BackColor)
           <button type="submit" class="inputbutton" style="position: absolute; bottom: 5px; right: 5px;">Save</button>    

 public JsonResult SaveGeneralSettings(int widgetid, StandardSettings mdl)
            var item = _contentManager.Get<CustomStyle>(widgetid);
            if (item != null) {
                     string css = item.CssStyle;
                     var col = ParseStringTocssCollection(item.CssStyle);

                     col["background-color"] = mdl.BackColor;

                     item.CssStyle = CssCollectionTostring(col);

                    return Json(new { s = "Success" });  

Aug 14, 2012 at 12:14 PM

Never mind. Found it. 

It was a javascript error in my module , not related to orchard.