Note that there are some explanatory texts on larger screens.

plurals
  1. POMvc4 RTM validation throwing an error
    text
    copied!<p>Has something changed with the rtm bits regarding the validation of models.</p> <p>I have a simple viewmodel that looks like</p> <pre><code> public class ProductViewModel { [Required] [DataMember(IsRequired = true)] public int ProductTypeId { get; set; } public string Product { get; set; } } </code></pre> <p>(I just added the DataMember(IsRequired = true) as the error message I get says to use it to fix the problem. However no joy)</p> <p>Within my controller the model state is telling me model is valid however when I try passing the model to my api using RestSharp I get the following error.</p> <blockquote> <p>{"Message":"An error has occurred.","ExceptionMessage":"Property 'ProductTypeId' on type 'Mine.Model.Model' is invalid. Value-typed properties marked as [Required] must also be marked with [DataMember(IsRequired=true)] to be recognized as required. Consider attributing the declaring type with [DataContract] and the property with [DataMember(IsRequired=true)].","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Validation.Validators.ErrorModelValidator.Validate(ModelMetadata metadata, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ShallowValidate(ModelMetadata metadata, ValidationContext validationContext, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.Validate(Object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, String keyPrefix)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.&lt;>c_<em>DisplayClass1.b</em>_0(Object model)\r\n at System.Threading.Tasks.TaskHelpersExtensions.&lt;>c__DisplayClass36<code>1.&lt;&gt;c__DisplayClass38.&lt;Then&gt;b__35()\r\n at System.Threading.Tasks.TaskHelpersExtensions.&lt;&gt;c__DisplayClass49.&lt;ToAsyncVoidTask&gt;b__48()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func</code>1 func, CancellationToken cancellationToken)"}</p> </blockquote> <p>I wasnt having this problem with the rc bits but then I have only started to use the restsharp libary with the rtm bits.</p> <p>Any help would be great.</p>
 

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