Geeks With Blogs
.Nettuce Code Salad

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<stringitems)
        {
            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 | Back to top


Comments on this post: Model Binding Checkboxes in MVC

# re: Model Binding Checkboxes in MVC
Requesting Gravatar...
You might want to try using templated Razor delegates:
http://weblogs.asp.net/nmarun/archive/2011/02/28/templated-razor-delegates-phil-haack.aspx

Arun
Left by Arun Mahendrakar on May 21, 2011 6:32 AM

# re: Model Binding Checkboxes in MVC
Requesting Gravatar...
Thanks for the great example, have really been looking at allot of terrible examples on this subject.
Left by Benjamin on Nov 11, 2012 1:25 PM

# re: Model Binding Checkboxes in MVC
Requesting Gravatar...
Short and very good explanation. thank you!
Left by Jo on Aug 19, 2013 7:24 PM

Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net