My Situation
I have a list of items(surveys) displayed on my home page. When I click the edit button for a particular item I have a modal pop up with the items details to edit. When the user clicks Save I submit the form via ajax. Depending on whether ModelState.IsValid == true I want to update the modal with validation information or close the modal and update the list of items with the new information.
This is how I am submitting the form:
$('#editSurveyForm form').live('submit', function () {
var f = $("#saveSurvey").parents("form");
var action = f.attr("action");
var serializedForm = f.serialize();
$.ajax({
type: "POST",
url: action,
dataType: "html",
data: serializedForm,
success: function (result) {
//TODO - I need an indicator that validation was successful
//If Validation Failed reload form with validation errors
$('#editSurveyModal').html(result);
//If Successful, reload Survey Partial View
//$('#surveyBox').html(result);
}
});
return false;
});
My Questions
The only thing I can think to do is return JSON from my controller with a flag indicating the state of the ModelState.IsValid and the corresponding partial that I should show.
1) How would I do this?
2) Is there a better way?
Update
I found this: http://www.klopfenstein.net/lorenz.aspx/render-partial-view-to-string-in-asp-net-mvc
but it seems more likely that I am going about the whole thing incorrectly.