GithubHelp home page GithubHelp logo

mikhail-tsennykh / mvccheckboxlist Goto Github PK

View Code? Open in Web Editor NEW
59.0 59.0 53.0 2.22 MB

Extends MVC HtmlHelper class so you can create POSTable checkbox list

Home Page: https://mikhail-tsennykh.github.io/MvcCheckBoxList/

C# 65.63% CSS 24.89% JavaScript 9.44% ASP 0.03% Batchfile 0.01%

mvccheckboxlist's People

Contributors

mikhail-tsennykh avatar tiesont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvccheckboxlist's Issues

Not Compatible with Unobtrusive Validation MVC4

I wont repeat everything as I have already written this up on StackOverflow only to come to the conclusion that my use of CheckBoxListFor breaks client and server side validation. The actual asp.net error I get is below.
http://stackoverflow.com/questions/13058900/mvc-4-unobtrusive-validation-on-objects-in-a-view-model

Server Error in '/Navigator' Application.

Value cannot be null.
Parameter name: source

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source

Source Error: 


Line 21: </div>
Line 22: <div class="editor-field checkbox">
Line 23: @Html.CheckBoxListFor(x => x.PostedGoals.GoalIDs,
Line 24:                       x => x.AvailableGoals,          
Line 25:                       x => x.Id,               

Source File: c:\inetpub\wwwroot\Navigator\Navigator\Areas\Client\Views\Stakeholder\_Form.cshtml    Line: 23 

Stack Trace: 


[ArgumentNullException: Value cannot be null.
Parameter name: source]
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +6101882
   MvcCheckBoxList.CheckBoxList_ModelBased(HtmlHelper`1 htmlHelper, ModelMetadata modelMetadata, String listName, Expression`1 sourceDataExpr, Expression`1 valueExpr, Expression`1 textToDisplayExpr, Expression`1 htmlAttributesExpr, Expression`1 selectedValuesExpr, Object htmlAttributes, HtmlListInfo wrapInfo, String[] disabledValues, Position position) +1169
   MvcCheckBoxList_Extensions_Model.CheckBoxListFor(HtmlHelper`1 htmlHelper, Expression`1 listNameExpr, Expression`1 sourceDataExpr, Expression`1 valueExpr, Expression`1 textToDisplayExpr, Expression`1 selectedValuesExpr, Position position, Expression`1 htmlAttributesExpr) +600
   ASP._Page_Areas_Client_Views_Stakeholder__Form_cshtml.Execute() in c:\inetpub\wwwroot\Navigator\Navigator\Areas\Client\Views\Stakeholder\_Form.cshtml:23
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +158
   ASP._Page_Areas_Client_Views_Stakeholder_Edit_cshtml.Execute() in c:\inetpub\wwwroot\Navigator\Navigator\Areas\Client\Views\Stakeholder\Edit.cshtml:16
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +853420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +837892
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

No longer works in MVC 3

All of the published DLLS (including Nu-Get) are now MVC4 based (System.Web.WebPages 2.0.0.0) and as such do not work on MVC 3 projects... The work around is to download the source, update the project file (to point to WebPages 1.0) and rebuild for a private distro...

Developing other extensions

I was glad to find the CheckBoxList extension. I just wanted to know whether you had it in mind (or whether it was easy) to convert this for usage with Radio Buttons and Drop Down Lists.

I ask because there are no elegant solutions for any of those "combined", meaning using the same type of conventions. For example, I use Radio Buttons with a Dictionary, and am using a Drop Down with SelectListItems. My models look like spaghetti code and I was just wondering whether or not this can be used with those other types of controls just to keep things uniform.

I'm not an experienced programmer, so the obvious answer might be that you cannot do that, but it would be nice :).

Sorry, but I didn't know where else I might post this that might get your attention (so it's not really an "issue").

ViewModel must be present

My data will not ALWAYS come from a view model, causing the Func<> to be superfluous... Then you have a check like this:

    if (htmlHelper.ViewData.Model == null)
    {
        throw new NoNullAllowedException(this.empty_model_message);
    }

which causes the html helper to crash the page when I have an empty collection.
In a Admin/Create scenario, MVC5 allows me to do have a null model

Input tags should use TagRenderMode.SelfClosing

The <input /> element is a self-closing tag. By using TagRenderMode.Normal when generating the checkbox controls, the tag generated is actually <input></input>, which is invalid. Webkit/Blink/Gecko seem to handle those tags internally, but Trident (IE) issues a slew of warnings.

Changing those items to TagRenderMode.SelfClosing will generate the correct markup.

How to validate checkbox list with data annotation

i use your code but when i use data annotation for validation then i notice no client side validation work. would you show how to validate checkbox list at client side with data annotation. discuss with sample code. thanks

If number of items is a multiple of number of columns, a useless break is created

When the number of checkbox to create is a multiple of the number of columns, the extension generates a row break that is not used.

In my case (new HtmlListInfo(HtmlTag.vertical_columns, 3)), it creates an empty DIV. In some cases it can break the display.

The cause are the lines 371-376 in ListBuilder.cs. The following if statement should include a test to check that it's not the last item:

if (htmlwrap_rowbreak_counter == htmlWrapper.separator_max_counter)

Overload function choice problem

I have two simple classes:

public class UserVM
{
       public IList<UserRoleVM> PreselectedUserRoles { get; set; }
       public IList<UserRoleVM> AllUserRoles { get; set; }
}

public class UserRoleVM
{
    public int Id {get; set;}
    public string Name {get; set;}
    public bool IsSelected {get; set;}
}

Year, i implement two ways to pass preselected items, but only because none of them works.

After that i calls:

@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
                                  user => user.AllUserRoles,
                                  x => x.Id,
                                  x => x.Name,
                                  ur => ur.IsSelected, // error here
                                  new { @class = "user-roles" })

And got error

CS1061: 'UserVM' does not contain a definition for 'IsSelected' and no extension method 'IsSelected' accepting a first argument of type 'UserVM' could be found (are you missing a using directive or an assembly reference?)

OK, i try:

@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
                                  user => user.AllUserRoles,
                                  x => x.Id,
                                  x => x.Name,
                                  user => user.PreselectedUserRoles, // error here
                                  new { @class = "user-roles" })

CS1061: 'UserRoleVM' does not contain a definition for 'PreselectedUserRoles' and no extension method 'PreselectedUserRoles' accepting a first argument of type 'UserRoleVM' could be found (are you missing a using directive or an assembly reference?)

But when i get rid of 6th param width custom HTML code - all works fine.

// OK
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
                                  user => user.AllUserRoles,
                                  x => x.Id,
                                  x => x.Name,
                                  user => user.PreselectedUserRoles
// OK
@Html.CheckBoxListFor(user => user.PostedUserRoles.UserRolesIds,
                                  user => user.AllUserRoles,
                                  x => x.Id,
                                  x => x.Name,
                                  ur => ur.IsSelected)

How can i use custom html tags with MvcCheckBoxList?

Cant Access @Html.CheckBoxList in View

Hello,

I just added the DLL to my MVC 3 project and I cant find @Html.CheckBoxList. I tried adding a @using to the view but I just cant find your Assembly name. What am I doing wrong?

HtmlTag.ul missing?

Upgraded to 1.4.3.0, and HtmlTag.ul is no longer a valid option. Is this removed for good or is this a bug?

listNameExpr shouldn't be a Func

I see that you expect the user to pass in a model with a future array that will be collected to the controller...
Instead, it should match a little better how ListBoxFor does it. I don't need a Func to setup the name on the client side.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.