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

本文关键字:虚拟 字符串 文本 填充 添加 Episerver | 更新日期: 2023-09-27 18:26:36

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

到目前为止,代码已经足够简单了。

来自区块类型:

    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>

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

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

你试图做的是行不通的,即使有一些方法可以使用这样的属性创建列表,我也不推荐它,因为它们是基于行的。这是一种可怕的做法。

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

<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>

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