The first pitch works as expected, but the next time it is completely sent back. I am using the jQuery.form plugin, specifically a call .ajaxSubmit(options)to submit a form. There are a couple levels of the div shell, but I am debugging the button.click bindings, and I can’t understand why the second time, even with the same variables, it makes a full post, and my partial view returns a completely new page.
here, buttonidand the screenidsame on both posts. I indicate this because they are calculated according to the naming convention, for example <name>Outer(wrapper), <name>(update target) and <name>Form(form to submit)
$('.formButton').click(function () {
var buttonid = $(this).attr('id');
var screenid = $('#' + buttonid).closest('div:not(.CSRForm)').attr('id').replace('Outer', '');
$('#' + screenid + 'Form').append('<input type="hidden" name="submitButton" value="' + buttonid.replace(screenid, '') + '" />');
$('#' + screenid + 'Form').submit();
});
the mind of the .formButtonelements is not inside the form, so I had to bind the submit event as such. My partial view returns a form, not buttons (they are dynamic)
here is .ajaxSubmit:
$('.CSRForm').submit(function () {
var needsValidation = "yes";
if (needsValidation) {
$(this).ajaxSubmit({
target: '#AccountSetup',
replaceTarget: false,
success: StepCallWithForm
});
return false;
}
});
and my MVC action, if it matters:
public ActionResult AccountSetup(AccountSetupViewModel vm, string submitButton)
{
if (!ModelState.IsValid)
{
return PartialView(vm);
}
else
{
return Content(submitButton + ",AccountSetup");
}
}
Edit:
Inserting this line directly into mine $(function() {:
$('#AccountSetup').ajaxForm();
I was able to stop the full postback. In Firebug, I now see the ajax postback to /CSR/Home/CSR?, where it all starts. It is like a form that has lost its validity. Are my events somehow cross?