3

I am using GetDataSourceItem Method from glass mapper to return my datasource item to the view, I debug the code when the datasource is empty the calloutModel in controller will be null, but from the view, model will not be null, it will have the current item model i am using the following code :

my controller action :

 public ActionResult Callout()
        {
            // I didn't fill the datasource in the component
            // calloutModel value is coming null.

            var calloutModel= GetDataSourceItem<CalloutModel>();
            return View(calloutModel);
        }

my view:

 @inherits Glass.Mapper.Sc.Web.Mvc.GlassView<CalloutModel>
 // Model is coming the current item in the view (it should be null)
Ayman Barhoum
  • 1,255
  • 1
  • 16
  • 31

1 Answers1

5

It looks like this is due to the GlassView base class. That class overrides the InitHelpers method and calls its GetModel method if the model is null. The GetModel method will fall back to the context item if there is no data source item.

To prevent this, you could change your @inherits directive to an @model CalloutModel and then use the @Html.Glass() helper to get access to the Editable methods and such.

Ben Golden
  • 1,580
  • 9
  • 16
  • that is working fine, and i can use editable method, but when i use render image like " @Html.Glass().RenderImage(item, x => x.Image)" i am getting error : "The call is ambiguous between the following methods or properties: RenderImage" – Ayman Barhoum Mar 22 '16 at 19:22
  • It is working fine now, you should provide the whole parameters to avoid ambitious issue : @Html.Glass().RenderImage(item, x => x.Image, null, isEditable: true) – Ayman Barhoum Mar 23 '16 at 07:41