ASP.NET MVC Form with multiple dropdowns and checkboxes group


ASP.NET MVC Form with multiple dropdowns and checkboxes group



I am lost with the submission of listbox with multiple itmes selected and with group of checkboxes.

If that was a WebForm project it wouldn't be a problem for me.

What are the best practices and maybe some code samples that show proper submission of form in ASP.NET MVC2 that contains group of checkboxes and listbox with mutiple selected items?

Here is the sample of the form:

Categories: - group of checkboxes

Topics: - listbox with multiple attribute (multiple="multiple")


Is a HTML helper a place for Business Logic?

1:

Is this code business logic or presentation logic?
As always start by defining the view model:. Sending collection of items in ASP.NET MVC
public class MyModel {     public bool Check1 { receive ; set; }     public bool Check2 { receive ; set; }      public IEnumerable<SelectListItem> ListItems { receive ; set; }     public string[] SelectedItems { receive ; set; } } 
Next the controller:. ASP.NET MVC forces an AJAX request be redirected to the login page when the FormsLogin session is no longer active
public class HomeController : Controller {     public ActionResult Index()     {         var model = new MyModel         {                Check1 = false,             Check2 = true,             ListItems = new SelectList(new[]             {                 new { Id = 1, Name = "item 1" },                 new { Id = 2, Name = "item 2" },                 new { Id = 3, Name = "item 3" },             }, "Id", "Name")         };         return View(model);     }      [HttpPost]     public ActionResult Index(MyModel model)     {         // TODO: Process the model         // model.SelectedItems will contain a list of ids of the selected items         return RedirectToAction("index");     } } 
and finally the View:. How to make a default editor template for enums?
<% using (Html.BeginForm()) { %>      <div>         <%: Html.LabelFor(x => x.Check1) %>         <%: Html.CheckBoxFor(x => x.Check1) %>     </div>      <div>         <%: Html.LabelFor(x => x.Check2) %>         <%: Html.CheckBoxFor(x => x.Check2) %>     </div>      <div>         <%: Html.ListBoxFor(x => x.SelectedItems, Model.ListItems) %>     </div>      <input type="submit" value="OK" />  <% } %> 
Asp.net MVC Visible/hide

93 out of 100 based on 68 user ratings 703 reviews