我正在使用果园画廊的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
有什么建议吗?
答案 0 :(得分:0)
您可以尝试删除视图顶部的@model声明,因为它是分配给模型的动态形状模板,而不是您期望的ViewModel - 请参阅http://orchard.codeplex.com/workitem/18195
您可以通过Model.Model访问视图模型,例如
@{
var myViewModel =
(Contrib.ChoiceList.ViewModels.ChoiceListFieldViewModel)Model.Model;
}
或直接访问动态字段
@Model.Model.Name