Orchardcms Orchard cms自定义选项列表字段,带有备选url

Orchardcms Orchard cms自定义选项列表字段,带有备选url,orchardcms,alternate,Orchardcms,Alternate,我正在使用orchard gallery的选择列表字段。到目前为止还不错 接下来,我对代码做了一些修改 Modules.Contrib.ChoiceList.views.EditorTemplate.Flieds.Contrib.ChoiceList.cshtml。 我们的目标是在单选按钮周围放一张桌子,它正在工作——没问题 使用以下代码: @model Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel @using O

我正在使用orchard gallery的
选择列表字段
。到目前为止还不错

接下来,我对代码做了一些修改
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>

有什么建议吗?

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

您可以通过模型访问视图模型

@{
    var myViewModel = 
        (Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel)Model.Model;
}
或者直接访问动态字段

@Model.Model.Name
@Model.Model.Name