model view controller - ASP.net MVC Get only the selected rows (checkbox) -


we using asp.net mvc , having trouble in selecting list of approved orders.

the orders approved selecting checkbox against each order.

eg..

order id product approved 1 book (depends if user selects checkbox or not) 2 pen (depends if user selects checkbox or not)

so doing this: , want know if there better way of implementating

view:

our false (as generated microsoft)

on post in controller action method: loop through orders (which list of order object) in response(order id) = true,false: select order or else dont select

but u see want avoid writing logic in controller.

so ideas ?

recently answered similar problem:

asp.net mvc checkbox group

you (it propable foreach loop):

<% int = 0; foreach(order o in model.orders) { %> <%= html.checkbox("orders[" + + "].checked") %> <%= html.hidden("orders[" + "].id",order[i].id) %> <%= html.hidden("orders[" + + "].checked",false) %> <% ++i; } %> 

your post method be:

[httppost] public actionresult test(ordersselection[] orders) {     var selectedorders = orders.where(o => o.checked);     return view(); } 

and model

public class ordersselection {      public bool checked { get; set; }      public bool id { get; set; } } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -