Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi can some one help me, post the form using ajax and then refresh the whole form ,
i am posting the form using below ajax method to controller, then in controller method save the data and will go the
redirect action method to reload the form and how can i get return success message in below is my code

code in view
try {
var data = new FormData(this.form);
$.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}
code in controller
[HttpPost]
public ActionResult SaveApplication(tr_applications Application, string OfficeHolder_id, int? AccountDetail_Id, string contact_person_id, IEnumerable<httppostedfilebase>specific_Item, IEnumerable<httppostedfilebase> Position_Description, IEnumerable<httppostedfilebase> Employment_Contract,IEnumerable<httppostedfilebase> Invoices_PhonePower, IEnumerable<httppostedfilebase> Lease_Rent,
IEnumerable<httppostedfilebase> Travel_Itinerary, IEnumerable<httppostedfilebase> Members_Travelling,
IEnumerable<httppostedfilebase> Capital_Works, IEnumerable<httppostedfilebase> Covering_Letter, IEnumerable<httppostedfilebase> Resolution_ToApply,
IEnumerable<httppostedfilebase> not_profitletter, IEnumerable<httppostedfilebase> schoolletter, IEnumerable<httppostedfilebase> affiliatedletter,
IEnumerable<httppostedfilebase> finanncialstatement, IEnumerable<httppostedfilebase> bankverification)
{
service.SaveApplication(Application, specific_Item, Position_Description,
Employment_Contract, Invoices_PhonePower, Lease_Rent, Travel_Itinerary,
Members_Travelling, Capital_Works, Covering_Letter, Resolution_ToApply,
not_profitletter, schoolletter, affiliatedletter, finanncialstatement, bankverification,
applicant_id, Applicant_Name);

if (OfficeHolder_id != "")
Applicant_Service.Update_ApplicationId_OfficeHolder(OfficeHolder_id, Application.application_id);

if (AccountDetail_Id != null && AccountDetail_Id != 0)
Applicant_Service.Update_Account_ApplicantionId(Convert.ToInt32(AccountDetail_Id), Application.application_id);

if (contact_person_id != "")
Applicant_Service.Update_ApplicationID_Contacts(contact_person_id, Application.application_id);

return RedirectToAction("EditApplication", new { Application.applicant_id, Application.application_id, OfficeHolder_id, AccountDetail_Id, contact_person_id });
}

What I have tried:

code in view
try {
var data = new FormData(this.form);
$.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}
Posted
Comments
Vijay Dodmani 22-May-17 7:44am    
try window.reload() function at the end of ajax success function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900