mikhail-tsennykh / mvccheckboxlist Goto Github PK
View Code? Open in Web Editor NEWExtends MVC HtmlHelper class so you can create POSTable checkbox list
Home Page: https://mikhail-tsennykh.github.io/MvcCheckBoxList/
Extends MVC HtmlHelper class so you can create POSTable checkbox list
Home Page: https://mikhail-tsennykh.github.io/MvcCheckBoxList/
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?
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.
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
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...
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?
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
Is there a way to remove the breaks after every checkbox?
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
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?
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)
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").
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.
The site http://mvccbl.com/ seems offline and as such the examples link doesn't work. Is it possible to publish the examples on a different site?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.