1
votes

I am using Glass mapper for mapping Sitecore item to class objects.

In one of the module when I pass null to a view, The model still has a value. It seems like it is inheriting page properties. Below are screenshots.

Screen shot 1: Passing null value to view

Screen shot 2: Model in view still has a value

Below is the code for Related_Content that is generated by TDS:

/// <summary>
/// Related_Content
/// <para></para>
/// <para>Path: /sitecore/templates/User Defined/PokerCentral/Component Templates/Data Templates/Callouts/Related Content</para>    
/// <para>ID: 2b54f9fd-1fb5-4638-98b0-0acd420c5b81</para>   
/// </summary>
[SitecoreType(TemplateId=IRelated_ContentConstants.TemplateIdString)] //, Cachable = true
public partial class Related_Content  : GlassBase, IRelated_Content
{

                    /// <summary>
            /// The Item Listing field.
            /// <para></para>
            /// <para>Field Type: Treelist</para>       
            /// <para>Field ID: 7a77a177-c5e0-4f74-9235-c5c6b709f7a0</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
            [SitecoreField(IRelated_ContentConstants.Item_ListingsFieldName)]
            public virtual IEnumerable<Guid> Item_Listings  {get; set;}

                    /// <summary>
            /// The Title field.
            /// <para></para>
            /// <para>Field Type: Single-Line Text</para>       
            /// <para>Field ID: 5abe46db-487c-4f1b-8a3c-d3e0ed515d9c</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
            [SitecoreField(IRelated_ContentConstants.TitleFieldName)]
            public virtual string Title  {get; set;}

                    /// <summary>
            /// The Base Category field.
            /// <para></para>
            /// <para>Field Type: Droplink</para>       
            /// <para>Field ID: 1cb2b0a4-f7e7-4cbe-b49b-7d660106365a</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
            [SitecoreField(IRelated_ContentConstants.Base_CategoryFieldName)]
            public virtual Guid Base_Category  {get; set;}

                    /// <summary>
            /// The Base Tags field.
            /// <para></para>
            /// <para>Field Type: Multilist with Search</para>      
            /// <para>Field ID: 072c54de-8fde-47f8-aaa0-2b0b1bd8843b</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
            [SitecoreField(IRelated_ContentConstants.Base_TagsFieldName)]
            public virtual IEnumerable<Guid> Base_Tags  {get; set;}


}

Can someone let me know how can I fix this?

1
You have to try to change the name of your object. I already see this problem. The mapping do something magical and maybe try to get any information for the property in some cache or something like that. - dpfauwadel
Object name which is "Related_Content" in my case is generated from TDS(Team Development Server). In such case how can I change the name and more over we need a Model of type "Related_Content" passed to view. - Akhil
Can you please post the code for the mode Related_Content ? - Ahmad Harb
@AhmadHarb I have updated my question with "Related_Content" code. Please verify. - Akhil
@Arjun can you try to pass Cachable = false in the SitecoreType attribute, it has nothing to do with the passed value of the object but let's give it a try. - Ahmad Harb

1 Answers

1
votes

You are inheriting from GlassView<Related_Content> Glass loads the model automatically if your rendering is on context item.

If you want to pass the model from controller don't inherit from Glass view instead use @model Related_Content

By looking at your code, your are passing data source to your view. if you are inheriting from Glass View, It will loads the data source into the model.