I'm currently following the online Sitecore developer formation (official) and i'm unfortunately having troubles to go any further due to a compilation error while trying to preview an item.
Basically, all what i'm trying to do is, binding a component statically, as explained in the lab. In order to do that, i created a controller, a model class and a view :
Controller:
using Sitecore.Mvc.Presentation;
using Sitecore.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Models;
namespace Website.Controllers
{
public class EventIntroController : Controller
{
// GET: EventIntro
public ActionResult Index()
{
return View(CreateModel());
}
private static EventIntro CreateModel()
{
var item = RenderingContext.Current.ContextItem;
var eventIntro = new EventIntro()
{
Heading = new HtmlString(FieldRenderer.Render(item,"ContentHeading")),
EventImage = new HtmlString(FieldRenderer.Render(item, "Event Image","mw=400")),
Highlights = new HtmlString(FieldRenderer.Render(item, "Highlights")),
Intro = new HtmlString(FieldRenderer.Render(item, "ContentIntro")),
StartDate = new HtmlString(FieldRenderer.Render(item, "Start Date")),
Duration = new HtmlString(FieldRenderer.Render(item, "Duration")),
Difficulty = new HtmlString(FieldRenderer.Render(item, "Difficulty Level")),
};
return eventIntro;
}
}
}
Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Website.Models
{
public class EventIntro
{
public EventIntro() { }
public HtmlString Heading { get; set; }
public HtmlString Intro { get; set; }
public HtmlString Body { get; set; }
public HtmlString EventImage { get; set; }
public HtmlString Highlights { get; set; }
public HtmlString StartDate { get; set; }
public HtmlString Duration { get; set; }
public HtmlString Difficulty { get; set; }
}
}
View:
@model Website.Models.EventIntro
<header>
<h1>@Model.Heading</h1>
</header>
<!-- [Event Details] -->
<div class="well">
<p class="text-muted">@Model.StartDate</p>
<p class="text-muted">Duration: @Model.Duration</p>
<span class="text-muted">Difficulty:</span>
<div class="difficulty-circle">
<input type="radio" name="group-2" id=group-2-0 value=10 />
<label class=red for=group-2-0></label>
<input type="radio" checked="checked" name="group-2" id=group-2-1 value=9 />
<label class=red for=group-2-1></label>
<input type="radio" name="group-2" id=group-2-2 value=8 />
<label class=red for=group-2-2></label>
<input type="radio" name="group-2" id=group-2-3 value=7 />
<label class=yellow for=group-2-3></label>
<input type="radio" name="group-2" id=group-2-4 value=6 />
<label class=yellow for=group-2-4></label>
<input type="radio" name="group-2" id=group-2-5 value=5 />
<label class=yellow for=group-2-5></label>
<input type="radio" name="group-2" id=group-2-6 value=4 />
<label class=green for=group-2-6></label>
<input type="radio" name="group-2" id=group-2-7 value=3 />
<label class=green for=group-2-7></label>
<input type="radio" name="group-2" id=group-2-8 value=2 />
<label class=green for=group-2-8></label>
<input type="radio" name="group-2" id=group-2-9 value=1 />
<label class=green for=group-2-9></label>
</div>
</div>
<!-- [/Event Details] -->
<!-- [Event Content] -->
<div class="lead">
@Model.Body
</div>
<div class="article image">
@Model.EventImage
</div>
<div class="highlights">
<h4>Trip @Sitecore.Globalization.Translate.Text("Highlights")</h4>
@Model.Highlights
</div>
<!-- [/Event Content] -->
I also created a new rendering in the layout/renderings folder of my Sitecore instance(through Sitcore Rocks). Then in another view, i call it this way:
@*@Html.Sitecore().Rendering("/sitecore/layout/Renderings/TAC/Events/Event Intro")*@
With the help of Sitecore Rocks, i simply synchronized the folders containing all those files copied above and i get the following error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Website' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 26: using System.Web.Optimization; Line 27: using System.Web.Routing; Line 28: using Website; Line 29: Line 30:
line 1 "C:\inetpub\wwwroot\ssd.tac.local\Website\Views\TAC\Events\Layouts\Events.cshtml"
Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a832d361\1901ffbf\App_Web_events.cshtml.9351e6fa.xdrjtduy.0.cs Line: 28
Thanks in advance for your help