Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

MVC: why controller method with JsonResult return html ? #2493


User avatar
0
sergii created

Hi, Could somebody help to understand why any AbpValidationException is returned as html for the conntroller method call like below ?

public class ExampleController : AbpController
{
        [HttpPost]
        [WrapResult(WrapOnSuccess = true, WrapOnError = true)]
        public JsonResult ProcessSubmitAction(MyFormViewModel vm)
        {
            var response = new AjaxResponse(true);
            try
            {
              // my logic here
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error = new Abp.Web.Models.ErrorInfo(ex.Message);
            }

            return Json(response);
        }
}

    public class MyFormViewModel 
    {
        [Required(AllowEmptyStrings = false, ErrorMessage = ValidationMessages.EmailRequired)]
        [StringLength(Abp.Authorization.Users.AbpUserBase.MaxEmailAddressLength, ErrorMessage = ValidationMessages.EmailLengthExceeded)]
        [EmailAddress(ErrorMessage = ValidationMessages.EmailFormatInvalid)]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }

        public string ReturnUrl { get; set; }
    }
$http.post('Example/ProcessSubmitAction', { Email: 'invalidemailvalue' })
                    .then(onSuccess, onError)
                    .finally(onFinished);

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It might be the same case with this one <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1154">https://github.com/aspnetboilerplate/as ... ssues/1154</a>.

  • User Avatar
    0
    sergii created

    Yes, this is it. Why customErrors setting change content type of a response? - this this unexpected behavior for UI. Developers should switch off custom errors to check appropriate response handlers... not very useful.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    ABP handles errors only when customErrors are enabled, this is the way of MVC. See <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Handling-Exceptions">http://aspnetboilerplate.com/Pages/Docu ... Exceptions</a>