Hi have a page that loads a jQuery modal dialog, the modal contains a form. How can i return an error so that it loads in the modal, if i return a PartialView, the page just loads with the dialog form contents (which is just intended to be in the modal)
here is the view
<span><a id="end" href="#">Launch End Dialog</a> </span>
<div id="end-dialog" class="dialog">
<div id="end-inner"></div>
<hr />
</div>
<script type="text/javascript">
$(function () {
var endDialog = $("#end-care-plan-dialog").dialog({
});
$("#end").click(function () {
endDialog.dialog('close');
});
$('#end').click(function () {
$('#end-inner').load(baseUrl + "/End", $.param({ id: '@Model.id' }),
function () {
endDialog.dialog('open');
});
});
});
</script>
heres my controller
[HttpPost]
public ActionResult End(EndVM end)
{
if (ModelState.IsValid)
{
//do work
}
//return so that pop up now has validation errors
return PartialView(end);
}
Note - jquery.validate and jquery.validate.unobstrusive are loaded into the views
Thanks hope this makes sense.
Update: Diego - this is the partial view that contains the form (that is loaded into the moal)
@using (Html.BeginForm<EndController>(c => c.End(@Model.Id)))
{ @Html.HiddenFor(m => m.Id) @Html.DropDownListFor(m => m.EndReasonId, RefData.EndReasons) Other Reason @Html.EditorFor(m => m.EndReasonOther) @Html.ValidationMessageFor(m => m.EndReasonOther) @(Html.ActionLink(c => c.Edit(@Model.Id), "Cancel")) @Html.SubmitButton("End", "End") }
Is there where i adapt your code?
Thanks