MVC复选框选中方法

1、Model类

    public class News
    {
        public int ID { get; set; }
        public string Name { get; set; }

    }

2、Controller返回数据

        private List GetALL()
        {
            List list = new List();
            for (int i = 0; i < 100; i++)
            {
                list.Add(new News { ID = i, Name = "我是ID" + i });
            }
            return list;
        }
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult AjaxPaging(int id = 1)
        {
            var model = GetALL().OrderBy(a => a.ID).ToPagedList(id, 5);
            if (Request.IsAjaxRequest())
                return PartialView("_AjaxPagingList", model);
            return View(model);
        }

3、View页面

一、AjaxPaging.cshtml 页面

@{
    ViewBag.Title = "分页";
}
@model PagedList
@Html.Partial("_AjaxPagingList", Model)
@section scripts { @{Html.RegisterMvcPagerScriptResource();} }


二、_AjaxPagingList.cshtml 页面

@model PagedList

@{ Html.RenderPartial("_AjaxPagingTable"); }
@Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "
  • {0}
  • ", DisabledPagerItemTemplate = "
  • {0}
  • ", PagerItemTemplate = "
  • {0}
  • " }, new MvcAjaxOptions { UpdateTargetId = "news", OnSuccess = "handleSuccess" })

    三、_AjaxPagingTable.cshtml 页面

    @model PagedList
    
        @foreach (var item in Model)
        {
            
        }
    
    复选框 @Html.DisplayNameFor(model => model.ID) @Html.DisplayNameFor(model => model.Name)
    @Html.DisplayFor(modelItem => item.ID) @Html.DisplayFor(modelItem => item.Name)





    你可能感兴趣的:(.net,C#,Mvc,.net,C#,mvc,checkbox)