繁体   English   中英

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

[英]Episerver add new virtual string textbox after its filled

我刚刚开始学习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>

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

即使有些方法可以使用诸如此类的属性来创建列表,我也不推荐这样做,因为它们将基于行。 这是一种可怕的做法。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM