ASP.NET MVC CheckBoxList from model with List Property

前端 未结 4 1458
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 07:01

Apologies if the title is unclear.

I\'m trying to return my model from a form submit in ASP.NET MVC.

My question is nearly the same as this question, only di

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 07:33

    Post a list of check boxes to server and get list of checked items
    linq left join to check whether checked, generating checkboxes,received checked list

    View

        List ModList = db.tbl_ISOCetificate.ToList();
    
        var li = (from cert in db.tbl_ISOCetificate join comCert in db.tbl_CompCertificate on cert.Cert_id equals comCert.CompCer_id into jo from b in jo.DefaultIfEmpty()
                  select new {cert.Cert_id,cert.Cert_Name,chkd = b.CompCer_SerId==null?"":"checked"}).ToList();
    
    
        foreach (var item in li)
        {       
            @:
    @: @: @:
    }

    Controller

      [HttpPost]
        public ActionResult ManageSurveyGroup(int[] CheckedCertificates)
        {
            return View();
        }
    

提交回复
热议问题