{"action":"created","issue":{"url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/163","labels_url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/163/comments","events_url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/163/events","html_url":"https://github.com/mikeedwards83/Glass.Mapper/issues/163","id":98674299,"number":163,"title":"View rendering with unpublished datasource item resulting in error","user":{"login":"hiraldesai","id":1005174,"avatar_url":"https://avatars.githubusercontent.com/u/1005174?v=3","gravatar_id":"","url":"https://api.github.com/users/hiraldesai","html_url":"https://github.com/hiraldesai","followers_url":"https://api.github.com/users/hiraldesai/followers","following_url":"https://api.github.com/users/hiraldesai/following{/other_user}","gists_url":"https://api.github.com/users/hiraldesai/gists{/gist_id}","starred_url":"https://api.github.com/users/hiraldesai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hiraldesai/subscriptions","organizations_url":"https://api.github.com/users/hiraldesai/orgs","repos_url":"https://api.github.com/users/hiraldesai/repos","events_url":"https://api.github.com/users/hiraldesai/events{/privacy}","received_events_url":"https://api.github.com/users/hiraldesai/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-03T05:20:15Z","updated_at":"2015-08-04T01:14:46Z","closed_at":null,"body":"I'm using interfaces as my viewmodels for a hybrid WebForms and MVC Sitecore project. All my view renderings have their \"Model\" field left empty with views having `@inherits GlassView<IModel>` in them to dynamically bind data to them. This approach works fine except for an edge case scenario where the datasource item defined for the view rendering is not published resulting in this \"The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type `IModel`\" error.\r\n\r\nThis error happens because both `GetModel` and `GetModelFromView` result in null passing the control back to Sitecore which then passes an item of type `RenderingModel` to the view.\r\n\r\nTo get around this - I tried setting \"Model\" field on the view rendering to the type of the model (e.g. `NameSpace.IModel, Website` - but that results in \"Constructor on type `Namespace.IModel` not found\" error.\r\n\r\nCan someone please advise if 1) I'm doing something wrong here 2) there is any way to get around this problem?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/comments/127445990","html_url":"https://github.com/mikeedwards83/Glass.Mapper/issues/163#issuecomment-127445990","issue_url":"https://api.github.com/repos/mikeedwards83/Glass.Mapper/issues/163","id":127445990,"user":{"login":"hiraldesai","id":1005174,"avatar_url":"https://avatars.githubusercontent.com/u/1005174?v=3","gravatar_id":"","url":"https://api.github.com/users/hiraldesai","html_url":"https://github.com/hiraldesai","followers_url":"https://api.github.com/users/hiraldesai/followers","following_url":"https://api.github.com/users/hiraldesai/following{/other_user}","gists_url":"https://api.github.com/users/hiraldesai/gists{/gist_id}","starred_url":"https://api.github.com/users/hiraldesai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hiraldesai/subscriptions","organizations_url":"https://api.github.com/users/hiraldesai/orgs","repos_url":"https://api.github.com/users/hiraldesai/repos","events_url":"https://api.github.com/users/hiraldesai/events{/privacy}","received_events_url":"https://api.github.com/users/hiraldesai/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T01:14:46Z","updated_at":"2015-08-04T01:14:46Z","body":"After debugging through the code - I think the issue lies in this method:\r\n\r\n```\r\n        protected virtual object GetFromField(Rendering rendering, GetModelArgs args)\r\n        {\r\n            Item obj = rendering.RenderingItem.ValueOrDefault(i => i.InnerItem);\r\n            if (obj == null)\r\n                return null;\r\n            return rendering.Item == null\r\n                ? null\r\n                : GetObject(obj[ModelField], rendering.Item.Database, rendering);\r\n        }\r\n```\r\n\r\nBasically `rendering.Item` is null but `rendering.DataSource` is set to an item id that only exists in the master database (unpublished item). Ideally, I'd like an empty model of the specified type returned here instead of Sitecore's getModel pipelines picking it up and resulting in errors."}}