Base solution for your next web application
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)