So I'm going to create Editor Template for Book Model in my application.
Book.cs
public class Book { public int BookId { get; set; } public string BookName { get; set; } public string Description { get; set; } }Then I'm going to create folder as EditorTemplates in Shared folder and add new view Book.cshtml as following.(The Name of the Template should be same as Class Name)
.
@model MySimpleEditorTemplate.Models.Book
@Html.DisplayFor(p => p.BookId) | @Html.EditorFor(p => p.BookId) |
@Html.DisplayFor(p => p.BookName) | @Html.EditorFor(p => p.BookName) |
@Html.DisplayFor(p => p.Description) | @Html.EditorFor(p => p.Description) |
Then in view page simply we can add editor for book as
@Html.EditorFor(model => model.Book)
then it will display above block
Simple and clear article - thanks Dinesh!
ReplyDelete