【问题标题】:Orchard cms Custom choice list field with url AlternateOrchard cms 带有 url 的自定义选择列表字段 Alternate
【发布时间】:2012-12-31 12:50:42
【问题描述】:

我正在使用来自果园画廊的Choice List Field。到目前为止一切顺利..

接下来我对代码做了一些改动 Modules.Contrib.ChoiceList.views.EditorTemplate.Flieds.Contrib.ChoiceList.cshtml。 目标是在单选按钮周围放置一个表格,它正在工作 - 没问题。

使用以下代码:

    @model Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel
    @using Orchard.Utility.Extensions;
    @{ var i = 0; }


    <fieldset class="FieldSoubedenos">
    <legend>@Model.Name</legend>
    <table class="data-table-Soubedenos">
        <tbody>
        <tr >    
            @if( Model.ListMode == "radio" )
            {
                foreach (var option in Model.Options.Split(';'))
                {

                    if( string.IsNullOrWhiteSpace(option) )
                    {

                        <td>
                            <label>@Html.RadioButton("SelectedValue", "",     string.IsNullOrWhiteSpace(Model.SelectedValue))<i>unset</i></label>
                        </td>

                    }
                    else
                    {
                        <td>
                            <label>@Html.RadioButton("SelectedValue", option, (option == Model.SelectedValue))@option</label>
                        </td>
                    }  

                    ++i;
                        if (i % 2 == 0)
                        {  

                         @:</tr><tr>                                            
                        }               
                }         
            }


    else
    {
        @Html.DropDownListFor(m=>m.SelectedValue, new SelectList(Model.Options.Split(';'), Model.SelectedValue))
        @Html.ValidationMessageFor(m=>m.SelectedValue)
    }     
        <tr >
        <tbody>      
    </table>
</fieldset>

下一阶段是使用替代网址,我确实创建了一个 - ~/Themes/XXXXXXXXX/Views/EditorTemplate-Dform-url-homepage.cshtml

并将上述代码复制到备用文件中。

刷新浏览器时出现以下错误:


Server Error in '/' Application.
        The model item passed into the dictionary is of type
         'IShapeProxy82be9d7cba51459e888e92b32898011b', but this dictionary requires a model item  of type 'Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel'.
Description: An unhandled exception occurred during the execution of the current web  request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'IShapeProxy82be9d7cba51459e888e92b32898011b', but this dictionary requires a model item of type 'Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel'.

Source Error:


 Line 3:          @if (Model.Content != null) {
Line 4:              <div class="edit-item-content">
Line 5:                  @Display(Model.Content)
Line 6:              </div>
Line 7:          }


Source File: c:\00\01 projectos\xxxx\yyyyyyyy\NewWebSite.Orchard.Web\0\Orchard.Web.1.6\Orchard 0\Core\Contents\Views\Content.Edit.cshtml    Line: 5

有什么建议吗?

【问题讨论】:

    标签: orchardcms alternate


    【解决方案1】:

    您可以尝试删除视图顶部的@model 声明,因为它是分配给模型的动态形状模板,而不是您期望的 ViewModel - 请参阅 http://orchard.codeplex.com/workitem/18195

    您可以通过 Model.Model 例如访问视图模型

    @{
        var myViewModel = 
            (Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel)Model.Model;
    }
    

    或直接访问动态字段

    @Model.Model.Name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多