Please try the code from the blog post you mentioned and add this to your view.
@if (Model != null && Model.CurrentPage.Contacts != null) { foreach (var element in Model.CurrentPage.Contacts) { @Html.DisplayTextFor(m => element.Name) @Html.DisplayTextFor(m => element.Age) @Html.DisplayTextFor(m => element.PhoneNumber) } }
It works.
Thanks for your reply. I've tried the above code in my view. when i edit/create a block type. View shows nothing on the screen due to keyvalues appears as null.
I've copied the complete code below for your reference. Please let me know if i am wrong in my code below to make it work as same like in this link https://world.episerver.com/blogs/Per-Magne-Skuseth/Dates/2015/11/trying-out-propertylistt/
//Block class
public class KeyValueBlock
{
public virtual string Key { get; set; }
public virtual XhtmlString Content { get; set; }
}
//Block type
public class KeyValueContentListBlock : BlockData
{
[CultureSpecific]
[Display(
Name = "KeyValue",
Description = "Key Value List",
GroupName = SystemTabNames.Content,
Order = 1)]
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<KeyValueBlock>))]
public virtual IList<KeyValueBlock> KeyValues { get; set; }
}
//Property class under model and property folders
[PropertyDefinitionTypePlugIn]
public class KeyValuePropertyList : PropertyList<KeyValueBlock>
{
protected override KeyValueBlock ParseItem(string value)
{
return JsonConvert.DeserializeObject<KeyValueBlock>(value);
}
public override PropertyData ParseToObject(string value)
{
ParseToSelf(value);
return this;
}
}
//view file
@model KeyValueContentListBlock
@if (Model != null && Model.KeyValues != null)
{
foreach (var element in Model.KeyValues)
{
@Html.DisplayTextFor(m => element.Key)
@Html.DisplayTextFor(m => element.Content)
}
}
I want the text fields to show and add them in list items as like in the sample URL https://world.episerver.com/blogs/Per-Magne-Skuseth/Dates/2015/11/trying-out-propertylistt/
Hi Suresh
I don't think PropertyList supports complex types such as XHTMLString. Can you try with a regular string instead?
David
Hi David,
Thanks for sharing your comments.
I've removed XHTML string and triied with string instead. It's not working either. i think XHTL is not the problem here. If i try the same for page type and it works fine for page type but the problem does exist only for block type.
XHTML, i've used it for capturing html data on the screen.
If propertylist wouldn't work for block, Is there any solution exist for managing list items in block ?
Suresh
What's the specific issue? Can you edit the PropertyList values in the forms view of the block?
Hi David,
When i create a new block/open the existing one, the screen shows nothing for fields Key and Value (no error). I mean no option to add the items for key and value fields as mentioned in this sample link https://world.episerver.com/blogs/Per-Magne-Skuseth/Dates/2015/11/trying-out-propertylistt/
I doubt if propertylist would work for block types. if not propertylist, Is there any other way i could capture the list items for key and value, i mean any built in property exist in EPI ?
Or Should this be done with some logic using MVC controls like using gridview controls ? Basically the block contents (Key & Value list) will be accessed via web api from another application and it's not for rendering on epi site/page.
Suresh
Hi David,
No, I haven't tested it using webform view. Will it work in webform view ?
Because all my work done so far in Razor view.
Suresh
Hi Suresh
I meant the all properties view of the content as described here in the manual: http://webhelp.episerver.com/latest/cms-edit/all-properties-view.htm
David
Thanks David.
As you've mentioned it displays fine in all properties view.
Another doubt in saving the list items that captured in block. I want to store and retrieve the list items in long string in xml format. I've the below code in model properties
[PropertyDefinitionTypePlugIn]
public class KeyValuePropertyList : PropertyList<KeyValueBlock>
{
protected override KeyValueBlock ParseItem(string value)
{
return JsonConvert.DeserializeObject<KeyValueBlock>(value);
}
public override PropertyData ParseToObject(string value)
{
ParseToSelf(value);
return this;
}
}
Any help on the above please.
I am following this article for user to create list items using block. https://world.episerver.com/blogs/per-magne-skuseth/dates/2015/11/trying-out-propertylistt/
this article doesn't provide details about how the view should look like.
Have copied my view code below, unfortunately view doesn't show the controls to capture the list items for some reason.
view code :-
@model KeyValueContentListBlock
@if (Model != null && Model.KeyValues !=null)
{
foreach (var element in Model.KeyValues)
{
@Html.LabelFor(m => element.Key)
@Html.PropertyFor(x => element.Key)
@Html.LabelFor(m => element.Content)
@Html.PropertyFor(x => element.Content)
}
}
I am new to episerver and any help would be appreciated.