Hi Guys,
To create first page type in your EmptySite solution that is created in my last blog post. Please follow the below steps-
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace EmptySite.Models.Pages
{
[ContentType(DisplayName = "Start",
GUID = "4cc06328-5403-4c7d-86a5-b6f9d00c66c3",
GroupName = SiteGroupNames.Specialized, Order = 10,
Description = "The home page for a website with an area for blocks and partial pages.")]
public class StartPage : PageData
{
[CultureSpecific]
[Display(Name = "Heading",
Description = "If the Heading is not set, the page falls back to showing the Name.",
GroupName = SystemTabNames.Content, Order = 10)]
public virtual string Heading { get; set; }
[CultureSpecific]
[Display(Name = "Main body",
Description = "The main body uses the XHTML-editor you can insert for example text, images, and tables.",
GroupName = SystemTabNames.Content, Order = 20)]
public virtual XhtmlString MainBody { get; set; }
}
}
Once this is done. Now it’s time to create the controller for this StartPage.
Code should look like this
using AlloyTraining.Models.Pages;
using EPiServer.Web.Mvc;
using System.Web.Mvc;
namespace EmptySite.Controllers
{
public class StartPageController : PageController
{
public ActionResult Index(StartPage currentPage)
{
return View(currentPage);
}
}
}
Once you are done with the StartPageController. Now it time to render the start page properties and do this just create a view for this inside the views folder.
Once this is done. Update the model to use correct page type.
@model EmptySite.Models.Pages.StartPage
The index.cshtml look like this.
@using EPiServer.Web.Mvc.Html
@model EmptySite.Models.Pages.StartPage
<h1>
@Html.PropertyFor(m => m.Heading)
</h1>
<div>
@Html.PropertyFor(m => m.MainBody)
</div>
That’s all as a code point of view.
That’s all. Run the site using the URL – http://localhost:56501/
Thanks for reading this blog post I hope it helps
Thanks and regards
Ravindra S. Rathore