2

I've created a couple of custom regions within my Piranha CMS Installation but am having problems when I have any kind of text region within my custom region. The Editor will display and you can enter text but it doesn't save to the DB.

Here's my classes

using System;
using System.ComponentModel.Composition;
using Piranha.Extend;
using Piranha.Extend.Regions;

namespace MatchtechGroup.Models.Regions
{
[Export(typeof(IExtension))]
[ExportMetadata("InternalId", "SimpleTab")]
[ExportMetadata("Name", "Simple Tab")]
[ExportMetadata("Type", ExtensionType.Region)]
[Serializable]
public class SimpleTab : Extension, ITab
{
    public string Title { get; set; }
    public HtmlRegion Tab { get; set; }

    public SimpleTab()
    {
        Tab = new HtmlRegion();
    }
}
}

And my Manager template in Areas/Manager/Views/Extensions

@model MatchtechGroup.Models.Regions.SimpleTab
@{
    Layout = "";
}
<ul class="form">
    <li>
        @Html.LabelFor(m => m.Title)
        <div class="input">@Html.TextBoxFor(m => m.Title)</div>
    </li>
    <li>
        @Html.TextAreaFor(m => m.Tab, new { @class = "editor", @rows = 10 })
    </li>
</ul>

The manager interface renders my new region correctly in the page editor but will not save content from the Html Region. There are no errors displayed in the interface, I just don't get the 'This Page has saved' message bar appear or am I able to publish the page.

Any help would be much appreciated, feels like I'm missing something basic or just that I can't nest an HTML region within this custom region.

Thanks

4

1 回答 1

1

问题可能是您的 HtmlValue 在模型绑定器中无效,因此 Model.IsValid 为假。解决您的问题的最简单方法是将您的属性更改为:

public class SimpleTab : ...
{
  public string Title { get; set; }
  public string Tab { get; set; }
}

唯一的区别是在 Razor 标记中使用它时。如果您有一个名为MyTab的 SimpleTab 类型的区域,则语法将是(例如):

<div>
  <h3>@Model.Regions.MyTab.Title</h3>
  <div class="content">
    @Html.Raw(Model.Regions.MyTab.Tab)
  </div>
</div>

唯一的区别是@Html.Raw()确保尸体没有逃脱。

问候

/ 哈坎

于 2014-09-09T13:25:53.347 回答