1

我正在使用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

有什么建议么 ?

4

1 回答 1

0

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

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

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

或直接访问动态字段

@Model.Model.Name
于 2013-01-17T04:07:34.130 回答