Codefirst CheckBoxList and prevalues seem to need a comma in the array element?
Hi all,
I came across a strange problem the other day that I'm hoping is something that I've missed rather than a bug in Contour, so perhaps one of you lovely people could let me know! I'm creating a checkboxlist on a codefirst contour page, however I found that if I don't have a comma within the value entered into the array for the prevalues, that I get a:
Object of type 'System.String' cannot be converted to type 'System.Collections.Generic.List`1[System.String]'
error, however if I add a comma to the text in the array it works fine. To show you what I mean, the first code block below causes the error:
[Field(FormPages.Callout, FormFieldsets.Signup, Type = typeof(CheckBoxList), Prevalues = new[] { "Yes", "No" })] public List<string> Member { get; set; }
However this one is fine, notice the addition of an extra comma after Yes and No:
[Field(FormPages.Callout, FormFieldsets.Signup, Type = typeof(CheckBoxList), Prevalues = new[] { "Yes,", "No," })] public List<string> Member { get; set; }
Anyone able to shed some light on this or suggest an alternative approach?
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Umbraco.Forms.CodeFirst.FormManager.CreateFormBaseInstance(FormViewEventArgs e) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:line 187
at Umbraco.Forms.CodeFirst.FormManager.FormRenderController_FormValidate(Object sender, FormViewEventArgs e) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:line 33
at Umbraco.Forms.Mvc.Controllers.FormRenderController.ContourForm(FormViewModel model, Boolean captchaIsValid) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.Mvc\Controllers\FormRenderController.cs:line 178
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Codefirst CheckBoxList and prevalues seem to need a comma in the array element?
Hi all,
I came across a strange problem the other day that I'm hoping is something that I've missed rather than a bug in Contour, so perhaps one of you lovely people could let me know! I'm creating a checkboxlist on a codefirst contour page, however I found that if I don't have a comma within the value entered into the array for the prevalues, that I get a:
Object of type 'System.String' cannot be converted to type 'System.Collections.Generic.List`1[System.String]'
error, however if I add a comma to the text in the array it works fine. To show you what I mean, the first code block below causes the error:
However this one is fine, notice the addition of an extra comma after Yes and No:
Anyone able to shed some light on this or suggest an alternative approach?
Many Thanks.
Comment author was deleted
Hmm that's strange, will give it a try
Comment author was deleted
Hi Simon,
Just tested and it should work without the extra comma
When exactly are you getting the error, could you post a stacktrace
I tried created a new form code first with your example and that works...
Hi Tim,
Thanks for getting back so promptly. Here's the stacktrace from the detail of the exception, if you need anything else then please feel free to ask!
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Umbraco.Forms.CodeFirst.FormManager.CreateFormBaseInstance(FormViewEventArgs e) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:line 187
at Umbraco.Forms.CodeFirst.FormManager.FormRenderController_FormValidate(Object sender, FormViewEventArgs e) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:line 33
at Umbraco.Forms.Mvc.Controllers.FormRenderController.ContourForm(FormViewModel model, Boolean captchaIsValid) in c:\Program Files (x86)\teamcity\buildAgent\work\fdc2f0fcbbcef310\Umbraco.Forms.Mvc\Controllers\FormRenderController.cs:line 178
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Thanks in advance!
Simon
Comment author was deleted
Looks like it is happening in the validate method, so might be a bug there, checking it out now
Comment author was deleted
Ok can confirm that it's a bug, happens when you only select 1 item in the checkboxlist
Comment author was deleted
Added to our issue tracker http://issues.umbraco.org/issue/CON-331 will try to have a fix this week
Thanks Tim, will keep my eyes peeled for the fix!
Comment author was deleted
Ok think I found a fix :)
Could you try downloading http://nightly.umbraco.org/Umbraco%20Contour/3.0.10%20WIP/
And you'll just need to deploy Umbraco.Forms.CodeFirst.dll to your bin directory
Let me know if that fixes the issue for you
Cheers,
Tim
Hi Tim,
That's perfect, works like a treat now! Thanks for your help with this.
Cheers,
Simon
Comment author was deleted
Great, thanks for confirming!
is working on a reply...