如何在Asp.net MVC中为类创建对象

本文关键字:创建对象 MVC net Asp | 更新日期: 2023-09-27 17:58:40

我有类

 public class TabMasterViewModel : ITabMasterModel
    {
        [ReadOnly(true)]
        public int colID { get; set; }
        [DisplayName("FirstName")]
        public string FirstName { get; set; }
        [DisplayName("LastName")]
        public string LastName { get; set; }
    }

现在我想从数据库中删除以下三条记录

 [HttpPost]
        public ActionResult RemoveSelected(IList<TabMasterViewModel> TabMasters)
        {
            IList<TabMasterViewModel> TabMasters = new  IList<TabMasterViewModel>;  //this line is giving me an ERROR..
            List<string> dinosaurs = new List<string>();
            int[] colIDs = { 1034, 1035, 1036 };
            foreach (int colid in colIDs)
            {
                //TabMasters.Add(new TabMasterViewModel { colID = colid });
                TabMasterViewModel tvm = new TabMasterViewModel { colID = colid };
                TabMasters.Add(tvm);
                //_tabmasterService.Delete(tvm);
            }
            _tabmasterService.DeleteList(TabMasters);
            //return View(_tabmasterService.GetAll(x => (x.colID == 1034 || x.colID == 1035 || x.colID == 1036)));
            return RedirectToAction("Index");
        }

但我不适合写

IList<TabMasterViewModel> TabMasters = new  IList<TabMasterViewModel>

如何在Asp.net MVC中为类创建对象

IList<TabMasterViewModel> TabMasters = new  List<TabMasterViewModel>();

IList<>是接口,无法实例化。