Hot answers tagged

26 votes
Accepted

Accessing the Data Source of a Control

Controller: public class RotatorController : SitecoreController { public ActionResult Index() { var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource; var dataSource = ...
Corey Smith's user avatar
  • 2,708
24 votes
Accepted

C# MVC razor view - HtmlHelper does not contain a definition for 'Sitecore'

There's a web.config that has Sitecore references that should exist in the /Views that is probably not right. This can be a common occurrence if using a new .NET MVC Project in Visual Studio and it ...
Pete Navarra's user avatar
  • 14.6k
21 votes
Accepted

How do I implement Accelerated Mobile Pages (AMP) with Sitecore?

Because Sitecore supports server-side responsive rendering, it's very easy to use the Device feature of the CMS to support AMP. AMP Layout (using Razor) This example is adapted from Google's example ...
sitecorerick's user avatar
  • 2,329
16 votes
Accepted

Create controller rendering in SXA

You should. Here are few things that you should know. Without this div element your rendering will not be SXA compliant. If you decide to skip it you will lose following features/abilities: your ...
Alan Płócieniak's user avatar
14 votes
Accepted

How to redirect to another page or sitecore item in MVC

To do page redirection, simply do return Redirect(url); For a permanent redirect (e.g. for search engines), use return RedirectPermanent(url); Both of these return a RedirectResult which inherit ...
Mark Cassidy's user avatar
14 votes

why is my Richtext field not rendering as rich text?

Its because you are not using the Sitecore field render to render the field content. This code: var mainContent = Sitecore.Context.Item.Fields["Main Content"].Value; just outputs the raw ...
Richard Seal's user avatar
  • 20k
11 votes
Accepted

Is it possible to use conditional renderings with Sitecore MVC

Conditional renderings work fine with MVC. For version 8, you must have Analytics.Enabled set to true so you can get to the personalization section of the presentation. "Global" conditional ...
Richard Seal's user avatar
  • 20k
11 votes

Handle all Custom Errors in Sitecore MVC

So for Sitecore - a global error handler in the global.asax will not work properly. The better way to do it is to override the code that calls each rendering and handle the errors there. ...
Richard Seal's user avatar
  • 20k
10 votes
Accepted

Item not found when saving page in Experience Editor

So it's took me all of yesterday and most of today to figure this out. In the end it was nothing to do with my code or configuration at all. The log files showing some errors were a Red-Herring and ...
Adam Seabridge's user avatar
10 votes

Can we design the View renderings with multiple data sources?

You could create a new template to create datasource items that bundle your "multiple items" (in separate link type fields, or with a multi-select type field - as you want). This way you are able to ...
Gatogordo's user avatar
  • 20k
10 votes
Accepted

Custom Item Resolver not setting context item

The Pipeline that you want to focus in on is the mvc.getPageItem pipeline. <mvc.getPageItem patch:source="Sitecore.Mvc.config"> <processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem....
Pete Navarra's user avatar
  • 14.6k
10 votes
Accepted

@Html.Sitecore.Field is not rendering any values

@Html.Sitecore().Field("Property Name") only works when your model is Sitecore.Mvc.Presentation.RenderingModel. You are using a custom model. To use it in your case, you will need to pass in the item ...
Chris Auer's user avatar
  • 13.1k
10 votes
Accepted

Is it possible to combine Sitecore 9.1+DotNet+React Js

Yes - Sitecore JSS / Headless Services The officially supported Sitecore Headless Services has full support for ReactJS components on MVC pages in the form of Javascript Renderings or Client Side ...
Mark Gibbons's user avatar
  • 5,432
9 votes

Adding Views - VS Adds Scaffolding and NuGets

With MVC 5, you should have the option to add an MVC 5 View Page, like so, Using this option gives you a simple popup to type in a name, then it generates a cshtml file with no scaffolding. @{ ...
Chris Sulham's user avatar
  • 1,458
9 votes
Accepted

How to return 401 page instead of login page when logged in user doesn't have permission

Background When the ItemResolver processor executes, it determines the context item for the request based on the current URL. Additionally, it also performs a security check to see if the current ...
Kasaku's user avatar
  • 4,164
9 votes

How to Render Javascript per page or component?

An alternative to @Gatogordo's option is to use a modular approach to JavaScript using something like requirejs. I wrote a post about using requirejs to organize your js with Sitecore a while a go. ...
Richard Seal's user avatar
  • 20k
9 votes
Accepted

Programmatically add log information in all renderings (controller, view) HTML

Yes, you can do it by the following way. Configuration: <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <mvc.renderRendering&...
Tamás Tárnok's user avatar
8 votes
Accepted

Sitecore MVC - Controller Rendering - Experience Editing

Yes - you are using the Raw Value when you do @Html.Raw(Model.SampleItem.Text.Raw) - this bypasses the field renderer and so will not be editable in the Experience Editor. Instead of .Raw use ....
Richard Seal's user avatar
  • 20k
8 votes

Pass objects into ControllerRendering

The reason your model isn't being populated is because @Html.Sitecore().ControllerRendering("Module", "IssueSection", new { area = "Editorial", issueSectionViewModel = issueSection }) puts the ...
Corey Smith's user avatar
  • 2,708
8 votes
Accepted

InvalidOperationException: No route in the route table matches the supplied values

Methods like @Html.Action(), @Html.RenderAction etc. apparently requires a route with the {controller}/{action} pattern (even though it isn't actually relevant from what I can see). The config file ...
Søren Kruse's user avatar
  • 3,245
8 votes
Accepted

How to use Dynamic Placeholders

It sounds like you have added the component to a placeholder key called section - with dynamic placeholders there will be an extra bit of data appended to that. Depending on the version of dynamic ...
Richard Seal's user avatar
  • 20k
8 votes
Accepted

How to use a Helix feature for multiple sites with specific template source settings per site?

You're going about it wrong. Or - I should say - not in accordance with Helix principles. First and foremost, your idea of a common base template to be used on all websites is not recommended ...
Mark Cassidy's user avatar
8 votes
Accepted

Sitecore MVC Routing and Virtual Folders

What I ended up doing is registering a single route on pipelines/initialize: <pipelines> <initialize> <processor type="MyFramework.Routing.RegisterVirtualFoldersRoutes, ...
vandsh's user avatar
  • 1,651
8 votes
Accepted

How do I access Sitecore.Context.Item in normal MVC Controller

If it's an ajax call you just did from javascript to a normal MVC controller, there is no Sitecore.Context.Item there. What you can do is in your original Sitecore rendering write the id of your item ...
Marek Musielak's user avatar
  • 23.2k
7 votes
Accepted

Sitecore MVC - Images Inside foreach Loop & RenderingModel for Strongly Typed Views

As has been mentioned. You should do this in your Constructor action and view model. This is an example of how you could do this without and ORM. But really if you are not using an ORM you are making ...
Richard Seal's user avatar
  • 20k
7 votes

Sitecore MVC - Images Inside foreach Loop & RenderingModel for Strongly Typed Views

I'm not sure what code you have currently but in your controller you could do something like this to get the image urls for the sub items and return them in a view model: List<string> ...
Adam Seabridge's user avatar
7 votes

MVC equivalent of SecurityCheck Pipeline Processor

Like Mark Cassidy mentioned above, <mvc.requestBegin> would be a close "equivalent". I ran into a similar situation wanting non-authenticated users to be redirected to the <site loginPage="/...
vandsh's user avatar
  • 1,651
7 votes

Sitecore MVC - Controller Rendering - Output Image

There are a couple ways you can do this. In the Custom Item Generator, each field has a .Rendered property you can reference which just runs the field renderer on that field. Use this if you want to ...
Chris Sulham's user avatar
  • 1,458
7 votes

Passing a parameter to controller rendering through URL

I've done this before using a wildcard item for the parameter and a custom resolver processor that runs just after the ItemResolver - The ItemResolver should resolve to /sitecore/content/mysite/...
Richard Seal's user avatar
  • 20k
7 votes

How do I implement Accelerated Mobile Pages (AMP) with Sitecore?

I recommend to integrate Google AMP with Sitecore by overriding the following pipelines: httpRequestBegin to check whether it is an AMP request (for example, by /amp/ URL prefix or suffix) or not and,...
Kate Orlova's user avatar
  • 1,221

Only top scored, non community-wiki answers of a minimum length are eligible