I have something like this
public static DepartmentDocumentsViewModel GetViewModel(DepartmentDocument departmentDocument, IPageUrlRetriever pageUrlRetriever, IPageAttachmentUrlRetriever attachmentUrlRetriever) { return new DepartmentDocumentsViewModel { DepartmentDocumentID = departmentDocument.DepartmentDocumentID, Title = departmentDocument.Title, Type = departmentDocument.Type, File = departmentDocument.File, AttachmentPath = attachmentUrlRetriever.Retrieve(departmentDocument.Fields.File).RelativePath, Url = pageUrlRetriever.Retrieve(departmentDocument).RelativePath }; }
How would I handle the attachmentUrlRetriever for a null field?
this worked for me
AttachmentPath = departmentDocument.Fields.File == null ? null : attachmentUrlRetriever.Retrieve(departmentDocument.Fields.File).RelativePath,
I am trying to do it on the cshtml page but am getting an error
Cannot implicitly convert type 'System.Guid' to 'CMS.DocumentEngine.IAttachment'
Please, sign in to be able to submit a new answer.