Asp.net MVC uses PagedList. MVC to implement paging effect, mvcpagedlist. mvc

Source: Internet
Author: User
Tags custom name actionlink

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.