Geeks With Blogs
.Nettuce Code Salad May 2011 Entries
MVC CheckBoxListFor Helper Extension
This has been done a few times, here's my attempt: public static MvcHtmlString CheckBoxListFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression) where TValue : IEnumerable<object> { var name = expression.Body is ParameterExpression ? ((ParameterExpression)expre... : ((MemberExpression)expressi... var sb = new StringBuilder("<ul class='checkboxlist'>"); var values = ((IEnumerable<object>... ......

Posted On Friday, May 20, 2011 11:33 PM

Model Binding Checkboxes in MVC
Just so I don't forget, again, it's as simple as this: Controller: public class HomeController : Controller { public ActionResult Index() { return View(new []{"one", "two", "three"}); } [HttpPost] public ActionResult Index(IEnumerable<string... items) { return View("Result", items); } } View: @model IEnumerable<string> @using (Html.BeginForm()) { foreach (var item in Model) { @item <input type="checkbox" name="items" value="@item" /> } <input type="submit" value="submit" /> ......

Posted On Friday, May 20, 2011 10:04 PM

Copyright © Jon Canning | Powered by: GeeksWithBlogs.net