Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze.js not returning custom validation error messages from server
    primarykey
    data
    text
    <p>I'm having trouble figuring out why <strong>Breeze.js (0.84.3)</strong> does not return error messages to the client that are set by Custom Validation Attributes applied on the server model at the class level. I am able to reproduce this with the Breeze TODO KO sample as follows:</p> <pre><code>using System; using System.ComponentModel.DataAnnotations; namespace Todo.Models { [MyCustomValidator] // NEW public class TodoItem { public int Id { get; set; } [Required, StringLength(maximumLength: 30)] public string Description { get; set; } // Set to 'error' to trigger server error. public System.DateTime CreatedAt { get; set; } public bool IsDone { get; set; } public bool IsArchived { get; set; } } [AttributeUsage(AttributeTargets.Class)] // NEW public class MyCustomValidator : ValidationAttribute { public override Boolean IsValid(Object value) { var todo = value as TodoItem; if (todo.Description == "error") { ErrorMessage = "The TodoItem is not valid!"; return false; } return true; } } } </code></pre> <p>I would expect that the error message <em>"The TodoItem is not valid!"</em> would be returned to the client however Breeze seems to always return <em>"Value cannot be null. Parameter name: source"</em> from the server. It seems there is an exception happening at:</p> <pre><code>StackTrace: at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector) at Breeze.WebApi.EFContextProvider`1.SaveChangesCore(Dictionary`2 saveMap) at Breeze.WebApi.ContextProvider.SaveChanges(JObject saveBundle) at Todo.Controllers.TodosController.SaveChanges(JObject saveBundle) in c:\Users\RichardH\Downloads\Software\Web\breeze-runtime-plus-0.84.3\Samples\Todo\Todo\Controllers\TodosController.cs:line 41 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass13.&lt;GetExecutor&gt;b__c(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.&lt;&gt;c__DisplayClass5.&lt;ExecuteAsync&gt;b__4() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken) </code></pre> <p>Can anyone shed some light on how I can apply validations on the server to the entire model (not just to a single property/field)?</p> <p>Thanks, Richard</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload