How can I pass JSON objec from AJAX success function to Controller? I have this situation:
function order(model) {
$.p({
url: '@Url.Action("CompleteFrameBrandDetails", "PacCompleteFrame")',
data: { item: model },
var pacModuleModel = {
CustomerNumber: model.Data.CustomerNumber,
Language: model.Data.Language,
Comission: model.Data.Comission,
GlassXml: model.Data.GlassXml,
Price: model.Data.Price,
ReadOnly: model.Data.ReadOnly,
Mode: model.Data.Mode,
IframeUrl: model.Data.Mode
};
var url = '@Url.Action("GlassCompleteFrameView", "PacModule", new { b2bXml = "__xml__" })';
$('#details-container').html(url.replace("__xml__", JSON.stringify(model.Data))); //"<h2>Loading Complete Frame Module. Please wait...</h2>"
window.location.href = url.replace("__xml__", JSONstringify(pacModuleModel)); //JSON.stringify(result.Data.GlassXml); JSON.stringify(result.Data)
}
});
} else {
$.alert({
message: 'error while trying to load xml details'
});
}
}
});
I successfully get model in second Ajax call. But when passing to window.location I get null parameter in controller action. Here is my controller action code:
public ActionResult GlassCompleteFrameView(JsonResult model)
{
return View("Glass", model);
}
How should look like correct code to get my model from view to controller via javascript? Or should I use some other approach?
And bellow is my model:
public partial class PacModuleModel
{
private PacPermissionModel permissionModel;
public ModuleMode Mode { get; set; }
public string IframeUrl { get; set; }
public string CustomerNumber { get; set; }
public bool ReadOnly { get; set; }
public string GlassXml { get; set; }
public double? Price { get; set; }
public string Comission { get; set; }
public PacPermissionModel Permissions
{
get
{
if (permissionModel == null)
{
permissionModel = new PacPermissionModel();
}
return permissionModel;
}
}
public string Language { get; set; }
}
GlassCompleteFrame action:
public ActionResult GlassCompleteFrame(string b2bXml)
{
string mode = "5";
//If the Store isn't selected, redirect to HomePage
if (string.IsNullOrEmpty(_workContext.SelectedCustomerNumber))
{
return RedirectToRoute("HomePage");
}
else
{
PacModuleModel model = new PacModuleModel();
model.CustomerNumber = _workContext.SelectedCustomerNumber;
model.Language = _workContext.WorkingLanguage.UniqueSeoCode;
model.Comission = "";
model.GlassXml = b2bXml.Replace("\"", "\\\"");
int index = b2bXml.IndexOf("<price>") + "<price>".Length;
string p = b2bXml.Substring(index, b2bXml.IndexOf("</price>") - index);
model.Price = Convert.ToDouble(p, System.Globalization.CultureInfo.InvariantCulture);
model.ReadOnly = false;
model.Mode = ModuleMode.ByProduct;
model.IframeUrl = "http://ItkCompleteConfiEmbedded.aspx?lang=" + _workContext.WorkingLanguage.LanguageCulture;
return new JsonResult()
{
Data = new
{
Success = true,
Data = model
}
};
}
}