Results 1 to 2 of 2

Thread: [RESOLVED] setting @Html.ValidationSummary from Json Call

  1. #1
    Fanatic Member
    Join Date
    Feb 00
    Location
    Dunmow,Essex,England
    Posts
    892

    Resolved [RESOLVED] setting @Html.ValidationSummary from Json Call

    <p>Hi All,</p>
    <p>In My View I have the following code:</p>
    Code:
    $.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:
    Code:
    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

  2. #2
    Fanatic Member
    Join Date
    Feb 00
    Location
    Dunmow,Essex,England
    Posts
    892

    Re: setting @Html.ValidationSummary from Json Call

    I found a way round it from another forum.

    http://forums.asp.net/t/1718068.aspx...mary+with+Json

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •