This post action is called from a ajax jquery dialog.
When I have a template selected it should run the RedirectToAction method but the UnitController and GetTemplateRootUnits action is never hit?
What do I wrong?
[HttpPost]
public ActionResult Open(int selectedTemplateId)
{
if (ModelState.IsValid)
{
return RedirectToAction("GetTemplateRootUnits", "Unit", new { TemplateId = selectedTemplateId });
}
else
{
return LoadOpenTemplates();
}
}
my route table:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
);
my target controller/action to call:
[HttpGet]
public JsonNetResult GetTemplateRootUnits(int templateId)
{
IEnumerable<Unit> units = _unitDataProvider.GetTemplateRootUnits(templateId);
return new JsonNetResult(new { data = units });
}
function openTemplate(dlg, form) {
$.ajax({
url: $(form).attr('action'),
type: 'POST',
data: form.serialize(),
success: function (response) {
if (response.success) {
dlg.dialog("close");
$('#TreeDiv').empty();
loadUnits(response.data);
}
else { // Reload the dialog with the form to show model/validation errors
dlg.html(response);
}
}
});
}