I'm using Sitecore 8.2 and attempting to render Image and General Link fields as recommended in this post:

@model Company.Feature.Foo.Models.FooBarViewModel

But the resulting HTML is just the raw field values:

<image mediaid="{123e4567-e89b-12d3-a456-426655440000}" />
<link text="Something" linktype="internal" class="bar" querystring=""
      target="" id="{83d6de54-019d-4774-bfd9-ce79e0802a24}">

I've also tried the following and they don't work. The only difference I can see compared with the post I linked is that I'm using a custom @model class rather than RenderingModel.

@Html.Sitecore().Field("{123e4567-...}", Html.Sitecore().CurrentItem)
@Html.Sitecore().Field("FieldName", Html.Sitecore().CurrentItem)

To get around this, I've had to write my own HTML Helpers that only partially implement what Sitecore could do. Is this a known issue with the standard renderer and does anyone have a fix?

  • Can you give more details around what your view model looks like? Does it inherit from RenderingModel?
    – Richard Seal
    Jul 23 '18 at 14:06
  • You cannot use the Html.Sitecore().CurrentItem as it is not your model. Html.Sitecore().CurrentItem current rendering item or if no data source rendering item selected then it returns the current page as item. Jul 23 '18 at 14:56
  • Can you post the whole code of your cshtml file? Jul 24 '18 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.