开发者

C# how to get list of data from view into controller in MVC 3

Please anyone tell me, how to get all list of modified data from view into controller in mvc3 at the time of page submit.

t开发者_如何学JAVAhere are three columns in my view emp_id, emp_name and check box i only want to get only checked data into controller

public class ResetLogin
{
    public string EmpID         { get; set; }
    public string EmpName       { get; set; }
    public bool   Checkbox      { get; set; }
}


public class ResetUserAll
{
   public List<ResetLogin> ResetUser { get; set; }  
}



           [Get]
           ResetUsersAll alluser = new ResetUsersAll();
            List<ResetUser> resetUser = new List<ResetUser>();  
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ResetUser item = new ResetUser();
                item.EmpID = dr["emp_id"].ToString();
                item.EmpName = dr["emp_name"].ToString();
                resetUser.Add(item);
            }
            alluser.users = resetUser;
            return PartialView(alluser);


    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ResetUserAll(ResetUserAll model) -- model showing null value

thanks


The controller only gets the data that gets submitted by the browser, so for check boxes it will not be told about unchacked boxes.

Need a clearer discription of problem to answer any more than this.


  1. mark all checkbox with the same name (i.e. "Checkbox") and set to each checkbox appropriate value of EmpID
  2. modify method [AcceptVerbs(HttpVerbs.Post)] public ActionResult ResetUserAll(string[] Checkbox) { } in Checkbox array you will have only checked values.

it's for case if you want to get only this data.

if you want to go by your way please check model class of your view

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜