1

We're experiencing the 'No model set' error message in the markup where we are calling the Glass Editable method. This is present after adding the rendering via the Experience Editor and choosing to 'Create New Content' for the datasource.

No model set

at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression1 field, Expression1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in ~\Glass.Mapper.Sc\GlassHtml.cs:line 565

I'm assuming it's because after selecting to create the new Item the rendering is reloaded but before the Item has finished being created hence the Model not being set.

The code isn't particularly fancy

View

@if (Html.Glass().IsInEditingMode || !string.IsNullOrEmpty(Model.HeadingTitle))
{
    <h3>@Html.Glass().Editable(Model, x => x.HeadingTitle)</h3>
}
<div class="sitecore-content">
    @Html.Glass().Editable(Model, x => x.Information, x => Html.Sitecore().Field(I_BaseInformationConstants.InformationFieldName).ToString())
</div>

Controller

public ActionResult TextBlock()
{
    // GetLayoutItem method from GlassController
    var basicContent = GetLayoutItem<ITextBlock>();

    return View("/Views/Shared/Components/TextBlocks/TextBlock.cshtml", basicContent);
}

I can wrap the code in a Null check to prevent the error but then the Editable aren't present to enter content. Anyone address this problem before?

6
  • How do you get the Model for the View? If I understand correctly it works fine after reload the page? Commented May 5, 2017 at 15:44
  • Actually the error persists after a reload which is curious. However, changing to a pre-existing Datasource (i.e. one not just created by Create New Content') the error message disappears. However the error reappears when swapping back to the newly created datasource Commented May 5, 2017 at 16:05
  • What is this for - x => Html.Sitecore().Field(I_BaseInformationConstants.InformationFieldName).ToString() as a third parameter? And can you post the Controller Action code? Commented May 5, 2017 at 16:10
  • I assume you're using Glass V4? Are you specifying model items in Sitecore or expecting Glass to resolve the model for you? Also I assume the old and the new DS items are of the same template type?
    – jammykam
    Commented May 5, 2017 at 16:19
  • Are you doing anything special in the GetRenderingDatasource pipeline? Its odd that your items is not immediately available to you.
    – Chris Auer
    Commented May 6, 2017 at 3:18

1 Answer 1

3

As you said that it looks like it gets the web database not the master. If you post the whole GetLayoutItem<T>() methond then I can add a more precise answer, but it looks like that something wrong in that method.

Possible reason

I assume that you initialize somewhere an ISitecoreContext object and you use the GetItem<T>() method of ISitecoreContext. Could be that you initialize it as a Singleton if you are using IOC. But it should be at least LifestylePerWebRequest because if you call the new SitecoreContext() without parameters then it's using the context database. So if it's a Singleton then it uses always that database which was the context initially.

These are just assumptions but could be helpful if you have this case.

1
  • You were correct. In our IoC the Lifestyle of ISitecoreContext was set to Transient. So when hitting the front-end of the site first before accessing Sitecore the ISitecoreContext would be created and passed along with the web as the Context Database. Setting it to LifestylePerWebRequest ensured that context wasn't passed along Commented May 12, 2017 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.