【问题标题】:Sitecore MVC Disable Web EditSitecore MVC 禁用网页编辑
【发布时间】:2015-10-21 02:24:15
【问题描述】:

我想在使用 Html.Sitecore().Field(string fieldName, Item item, object params) 时禁用正在显示的字段的 Web 编辑,但我遇到了问题。以下抛出“参数计数不匹配”错误

@Html.Sitecore()
   .Field(item.InnerField.Name, item.InnerField.Item,
     new Sitecore.Collections.SafeDictionary<string, string>
     {
       {"class", classParam},
       {"disable-web-edit", pageEditorEnabled.ToString()}
     });

我不能使用匿名对象,因为 disable-web-edit 有连字符。可能还有其他一些我应该使用的关键字,但这就是字段渲染器使用 iirc 的原因。

[TargetParameterCountException: Parameter count mismatch.]
   System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +14255904
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +96
   System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) +37
   Sitecore.Mvc.Helpers.TypeHelper.CopyProperties(Object source, SafeDictionary`2 target) +89
   Sitecore.Mvc.Helpers.SitecoreHelper.BeginField(String fieldName, Item item, Object parameters) +120
   Sitecore.Mvc.Helpers.SitecoreHelper.Field(String fieldName, Item item, Object parameters) +23

【问题讨论】:

  • 你试过@Html.Sitecore().Field("Field Name", new { DisableWebEdit = true })吗?
  • 刚刚做了。解决了,谢谢。如果您想将其添加为答案,我会接受。还有我们可以作为参数传递的东西的完整列表吗?我们通常可以在没有连字符的情况下传递给字段渲染器吗?
  • 旁注:MVC 会自然地将带有下划线的 HTML 参数转换为破折号 - 不知道这是否直接适用于此。
  • 很高兴知道将数据属性应用于字段渲染器生成的元素。谢谢!

标签: sitecore sitecore8 sitecore-mvc


【解决方案1】:

尝试在这样的匿名对象中使用DisableWebEdit

@Html.Sitecore().Field("Field Name", new { DisableWebEdit = true })

您也可以为图像字段设置mw = 300, mh = 200

我不知道是否还有其他开箱即用的选项。

在字段渲染管道中无法识别的任何内容都将作为 HTML 属性添加到标签中。

【讨论】:

  • 您可以像 css 类一样添加参数,但它前面必须有一个 @。示例:新 { @class= "my-css-class" }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多