asp.net mvc tutorial for beginners
Lesson 136 of 496 · Part 26 Customizing the autogenerated index view · Database
Part 26 Customizing the autogenerated index view
In this video we will discuss, customizing the autogenerated index view. Please watch Part 25, before proceeding.
At the moment, the “Index” view is using “Name” as the column header for both employee name and department name. This is because “Name” column is used in both the database tables(tblEmployee & tblDepartment) and entity framework has used these column names to generate “Name” property in Employee and Department classes that are auto-generated.
I want to change the depratment column header to “Department Name” instead of just “Name”. To achieve this, add a class file with name=Department.cs” to “Models” folder.
Copy and paste the following code in “Department.cs” file.
[MetadataType(typeof(DepartmentMetaData))]
public partial class Department
{
}
public class DepartmentMetaData
{
[Display(Name=”Department Name”)]
public string Name { get; set; }
}
With these changes run the application and notice the column name is displayed as Department Name. This is achieved by using “Display” attribute that is present in “System.ComponentModel.DataAnnotations” namespace.
If you are wondering why can’t we apply “Display” attribute directly to the auto-generated “Department” class instead of creating another partial “Department” and DepartmentMetaData class. We can do it. There is nothing stopping us from doing it, but every time the Department class is auto-generated, our custom changes will be lost. This is the reason for creating another partial class, and applying our changes.
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/05/part-26-customizing-autogenerated-index.html
Slides
http://csharp-video-tutorials.blogspot.com/2013/09/part-26-customizing-auto-generated.html
All ASP .NET MVC Text Articles
http://csharp-video-tutorials.blogspot.com/p/aspnet-mvc-tutorial-for-beginners.html
All ASP .NET MVC Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-mvc-slides.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists