Take the community feedback survey now.
Take the community feedback survey now.
I don't have a solution for your DnB problem at the moment, but I do have a suggestion how you can do it in another way. I would just create two properties on the content type:
public virtual ContentReference ContactContentLink { get; set; }
public Contact Contact
{
get
{
if (ContentReference.IsNullOrEmpty(this.ContactContentLink))
return null;
return ServiceLocator.Current.GetInstance<IContentLoader>().Get<Contact>(this.ContactContentLink);
}
}
I would also consider if it's really needed to have the Contact property on the model itself. It could easily be populated on a view model or by using an extension method the get the Contact from the ContentReference.
Btw, you can create a display template for your ContentReference property called ContactReference.cshtml and put in i /Views/Shared/DisplayTemplates. This way you can drag and drop a contact and it will get updated instantly in the on-page edit view:
@using EPiServer.ServiceLocation
@model ContentReference
@{
Contact contact;
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
if (ContentReference.IsNullOrEmpty(Model) || contentLoader.TryGet(Model, out contact) == false)
{
return;
}
Html.RenderContentData(contact, false);
}
Then in your view where you want your contact. You can of course add a UIHint attribute to your property as well and skip the second parameter in the PropertyFor helper:
@Html.PropertyFor(m => m.ContactContentLink, "ContactReference")
Tnx for reply!
Yes, i'm aware of that. I just want clean models without unecessary properties :P I guess i could create a view model with the Contact typed property and have ContentRefernce property on my contenttype or something.
I this case i'm not rendering the property it self, the Contact object is just pure data that is used from contact blocks and such :)
I have this:
The property works as I like, but DnD is borken. I get an error in the UI: