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 = ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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....
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 ...
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 ...
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.
@{
...
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 ...
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.
...
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&...
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 ....
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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> ...
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="/...
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 ...
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/...
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,...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
mvc × 181presentation × 19
pipelines × 13
experience-editor × 12
glass-mapper × 12
sitecore-api × 9
routing × 9
wffm × 8
mvc-forms × 8
controller × 8
upgrade × 6
sxa × 5
best-practices × 5
webforms × 5
ajax × 5
helix × 4
templates × 4
links × 4
javascript × 4
css × 4
sitecore-client × 3
configuration × 3
fieldtype × 3
dynamic-placeholder × 3
razor × 3