Akhil
Akhil

Reputation: 165

Model has value even when null is passed to view through controller

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?

Upvotes: 1

Views: 424

Answers (1)

Dheeraj Palagiri
Dheeraj Palagiri

Reputation: 1879

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.

Upvotes: 1

Related Questions