PDA

Click to See Complete Forum and Search --> : VS 2010 [RESOLVED] setting @Html.ValidationSummary from Json Call


Bill Crawley
Sep 7th, 2011, 03:57 AM
<p>Hi All,</p>
<p>In My View I have the following code:</p>
$.ajax({
type: 'POST',
url: '/PolicyZone/JsonEditFloatingZone',
data: jSonData,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {

window.location.href = response.newLocation;
},
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
});
My Controller Has:
public JsonResult JsonEditFloatingZone(string available, string unavailable, int policyZoneID)
{
string newLocation = string.Concat("../../Edit/", policyZoneID);

string failReason = string.Empty;
try
{
PolicyZoneService.EditPolicyZoneFloatingZone(available, unavailable, policyZoneID, ref failReason);

if (failReason.Length != 0) { throw new Exception(failReason); }

return new JsonResult { Data = new { newLocation } };
}
catch (Exception ex)
{
throw;
}
}
Now when there is a failure, my controller drops into my exception handler as expected. but in dev,the IDE breaks on the Throw statement with 'exception was unhandled by code' ????
so that is my first problem. The next is rather than have the Alert show the error's, i'd like to update the ValidationSummary control instead.
Normally to do this, I'd pass the viewModel, use a ModelStateDictionary and add my error to this. However, in my Json call, I am not passing the model, so I dont have that luxury

Bill Crawley
Sep 22nd, 2011, 03:15 AM
I found a way round it from another forum.

http://forums.asp.net/t/1718068.aspx/1?how+do+I+get+my+Error+s+into+an+Html+ValidationSummary+with+Json