DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
222 stars 79 forks source link

Issue with CheckboxlistfromEnum #399

Closed RyanSeyAG closed 8 years ago

RyanSeyAG commented 8 years ago

i am getting this error when attempting to use checkboxlistfromenum. Am I missing something from the example

{System.NullReferenceException: Object reference not set to an instance of an object. at TwitterBootstrapMVC.Renderers.Renderer1.IsSelected(Object value, Enum e, Boolean isIEnumerable, Boolean isArray) at TwitterBootstrapMVC.Renderers.Renderer1.RenderInputListFromEnum(HtmlHelper1 html, BootstrapInputListFromEnumModel model) at TwitterBootstrapMVC.Controls.BootstrapInputListFromEnumBase2.ToHtmlString() at System.Web.HttpUtility.HtmlEncode(Object value) at System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) at System.Web.WebPages.WebPageBase.Write(Object value) at ASP._Page_Views_Home_Index_cshtml.Execute() in d:\Projects - AGOTools\AGORepository\AGO NuGet Packages\AGO.Web.BootstrapMVC.TestProj\Views\Home\Index.cshtml:line 18 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)}

DmitryEfimenko commented 8 years ago

maybe, maybe not. It'd be great to see an example of how you are using this method in the code, what are your values.

RyanSeyAG commented 8 years ago
@Html.Bootstrap().CheckBoxesFromEnumFor(x=> x.Trial).OrderByValue(true).DisplayInColumns(4, 5, true)

public class HomeViewModelcs { public Collection Trial { get; set; } }

public enum trial
{
    whammy, whammy2
}
DmitryEfimenko commented 8 years ago

the property public Collection Trial { get; set; } should be of the same type as your enum:

public trial Trial { get; set; }
DmitryEfimenko commented 8 years ago

actually, it should be an Enumerable of that enum:

public List<trial> Trial { get; set; }
RyanSeyAG commented 8 years ago

i think the model was not getting instantiated before it when. sorry about that. I was on a get and did not think about that

DmitryEfimenko commented 8 years ago

no problem, good luck!