This is the error I get using MVC2 with:
Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.
It is based on a [Mandatory] data validation.
Stack trace:
InvalidOperationException: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.] System.ComponentModel.DataAnnotations.ValidationAttribute.SetupResourceAccessor() +89338 System.ComponentModel.DataAnnotations.ValidationAttribute.FormatErrorMessage(String name) +38 System.Web.Mvc.<Validate>d__1.MoveNext() +215 System.Web.Mvc.<Validate>d__5.MoveNext() +735 System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) +424 System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +732 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +475 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +152 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709 System.Web.Mvc.Controller.ExecuteCore() +162 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
I welded the model of my view before that (it is interrupted at any time when there is an attribute [Required], it works fine without):
[Required(ErrorMessage = "")] [DataType(DataType.Text)] [DisplayName("Property Name")] public string MyProperty { get; set; }
My controller returns an empty ViewModel and the form in the view is completely empty ... just a submit button.
Ryan o'neill
source share