Episerver在填充后添加新的虚拟字符串文本框

时间:2015-12-14 02:13:59

标签: c# asp.net-mvc content-management-system episerver

我刚开始学习Episerver,我有一个包含3个文本框(虚拟字符串)的块,当我向它们添加内容时,数据会显示在视图的表中。我想用相同的方法用更多的数据填充表格,但由于增加的值绑定到文本框,我不知道该怎么做。我要么希望文本框在回发后为空,要么动态添加新的文本框。

到目前为止,代码很简单。

来自BlockType:

    public virtual string Namn { get; set; }

    public virtual string Innehåll { get; set; }

    public virtual int Pris { get; set; }

从视图:

<table class="table">
    <tr>
        <th>Namn</th>
        <th>Innehåll</th>
        <th>Pris</th>
    </tr>
    <tr>    
        <td @Html.EditAttributes(x => x.Namn)>@Html.DisplayFor(x => x.Namn)</td>
        <td @Html.EditAttributes(x => x.Innehåll)>@Html.DisplayFor(x => x.Innehåll)</td>
        <td @Html.EditAttributes(x => x.Pris)>@Html.DisplayFor(x => x.Pris)Kr</td>
    </tr>

1 个答案:

答案 0 :(得分:1)

首先,出于语义原因,您不应在字符串名称中使用åäö。

你想要做的事情不会工作,即使有办法使用这样的属性创建列表我不能推荐它,因为它们是基于行的。这是一种可怕的做法。

我建议您使用更简单的方法,并将表格包装在内容区域

<table class="table">
    <tr>
        <th>Namn</th>
        <th>Innehåll</th>
        <th>Pris</th>
    </tr>
    @Html.PropertyFor(x => x.YourContentArea)
</table>

稍微简化您的阻止

为了世界和平而重命名属性

public virtual string Name { get; set; }
public virtual string Content { get; set; }
public virtual int Price { get; set; }

在块视图中将此表替换为此行

<tr>    
    <td @Html.EditAttributes(x => x.Name)>@Html.DisplayFor(x => x.Name)</td>
    <td @Html.EditAttributes(x => x.Content)>@Html.DisplayFor(x => x.Content)</td>
    <td @Html.EditAttributes(x => x.Price)>@Html.DisplayFor(x => x.Price)Kr</td>
</tr>

您所要做的就是创建一个块实例并将其拖动到包装表的内容区域。

相关问题