Asp.net MVC uses PagedList. MVC to implement paging effect, mvcpagedlist. mvc
In ef db First in the previous article, there are two problems:
1. The Add/Edit page displays the property name rather than the custom name (for example, name, Major ...)
2. Verification not added when adding/editing
3. Data Display page
@ Html. labelFor (model => model. name, htmlAttributes: new {@ class = "control-label col-md-2"}) is the "label" for displaying the property Name. If the Display property is not specified, the property Name is directly displayed
Entity model files and codes generated by the general database are generally not directly modified (to prevent overwriting during next generation). Verification and entity separation are used here.
Add a verification class with the following code:
Using System. componentModel. dataAnnotations; namespace Zhong. web. models {[MetadataType (typeof (T_StudentValidateInfo)] public partial class T_Student {} public class T_StudentValidateInfo {[Display (Name = "Name")] [Required (ErrorMessage = "Name cannot be blank")] [StringLength (10, ErrorMessage = "Name length exceeds limit")] public string Name {get; set ;} [Display (Name = "student ID")] [Required] [StringLength (20, MinimumLength = 10, ErrorMessage = "Length: 10-20")] public string StudentId {get; set ;}}}
At this time, the front-end accesses and submits:
You can see that the Name is changed to "Name", and StudentsId is changed to "student ID". After you click the Create button, a verification prompt is displayed.
PagedList. MVC plug-in is used for real-time paging. You can add references to nuget.
Add a List Controller Method to StudentsController:
public ActionResult List(int page = 1){ //var students = entities.T_Student.OrderBy(s => s.Id).Skip((page - 1) * 2).Take(2); var students = entities.T_Student.OrderBy(s => s.Id); return View(students.ToPagedList(page, 2));}
The view code is as follows:
@ Using PagedList. mvc @ model PagedList. IPagedList <Zhong. web. models. t_Student> @ {ViewBag. title = "List" ;}< h2> List
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.