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)
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.