Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi Jiri,
The easy answer (probably) is to set it on your content type using:
public override void SetDefaultValues(ContentType contentType) { base.SetDefaultValues(contentType); Priority = MailPriority.Low, }
Do you have any reason not to use this approach?
/Jake
Ah, ok.
In Admin > Content Type can you navigate to a content type that is using your Priority property. What type is it? I'm expecting integer from your code above.
It’s Long string :-( but you intention was right. Setting it to int fixed the problem. I spent with it some hours. Thank you.
Hitting the "Revert to Default" button should fix that -- if I remember correctly.
I need to use System.Net.Mail.MailPriority as enum on property. I have found many recepies how to do it but none of them worked.
Code:
public class EmailPrioritySelectionFactory : ISelectionFactory { public IEnumerable GetSelections(ExtendedMetadata metadata) { return new[] { new SelectItem { Text = "Low", Value = MailPriority.Low }, new SelectItem { Text = "Normal", Value = MailPriority.Normal }, new SelectItem { Text = "High", Value = MailPriority.High }, }; } } [EditorDescriptorRegistration(TargetType = typeof(MailPriority))] public class EmailPriorityEditorDescriptor : EditorDescriptor { public EmailPriorityEditorDescriptor() { SelectionFactoryType = typeof(Business.SelectionFactories.CustomerServicePage.EmailPrioritySelectionFactory); ClientEditingClass = "epi-cms/contentediting/editors/SelectionEditor"; DefaultValue = MailPriority.Low; } }
Issue is that default value from editor descriptor is not mapped in any case. It takes 0 – normal. I am affraid I have found bug.
On setting
[EditorDescriptor(EditorDescriptorType = typeof(EditorDescriptors.EmailPriorityEditorDescriptor))] [BackingType(typeof(PropertyNumber))] public virtual MailPriority Priority { get; set; } or [SelectOne(SelectionFactoryType = typeof(EmailPrioritySelectionFactory))] [BackingType(typeof(PropertyNumber))] public virtual MailPriority Priority { get; set; }
on value change I got (XHR) response from server
[InvalidCastException: Specified cast is not valid.] Castle.Proxies.XYZabcProxy.get_Priority() +204 [TargetInvocationException: Property accessor 'Priority' on object 'Castle.Proxies.XYZabcProxy' threw the following exception:'Specified cast is not valid.'] System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +490 EPiServer.Validation.DataAnnotationsValidator`1.ValidateInstance(Object instance, List`1 validationResult, ValidationContext validationContext) +618 EPiServer.Validation.DataAnnotationsValidator`1.Validate(T instance) +183 EPiServer.Validation.Internal.ContextValidatorWrapper`2.Validate(Object instance) +103 EPiServer.Validation.Internal.ValidationService.ValidateRecursively(Object instance, Object context, HashSet`1 visitedInstances) +442 EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.UpdateContentProperties(ContentReference contentReference, IDictionary`2 properties, SaveAction saveAction) +796 EPiServer.Cms.Shell.UI.Rest.Internal.ContentDataStore.Patch(PatchContentDataModel entity) +357 lambda_method(Closure , ControllerBase , Object[] ) +139 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39 System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +77 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +72 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +387 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +387 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +38 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 EPiServer.Shell.Services.Rest.RestControllerBase.EndExecute(IAsyncResult asyncResult) +60 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128</></></></>
EPiServer.CMS.Shell.UI 11.4.4.0.
Am I doing something wrong in order to setup this simple enum selection on model?