1
votes

I want to disable web editing for a field being displayed while using Html.Sitecore().Field(string fieldName, Item item, object params) but I am having trouble. The following throws a "parameter count mismatch" error

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

I couldn't use an anonymous object because disable-web-edit has hyphens. There may be some other keyword that I'm supposed to be using but that's what field renderer uses 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
1
Have you tried @Html.Sitecore().Field("Field Name", new { DisableWebEdit = true })? - Marek Musielak
Just did. That worked out thanks. If you want to add that as an answer I'll accept it. Also is there a comprehensive list of things we can pass as parameters? Is it anything we can normally pass to field renderer without hyphens? - Teeknow
Side note: MVC will convert HTML parameters that have underscores to dashes naturally - don't know if that directly applies here. - Jim Noellsch
That's good to know to apply data attributes to elements produced by the field renderer. Thanks! - Teeknow

1 Answers

13
votes

Try to use DisableWebEdit in anonymous object like that:

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

You can also set mw = 300, mh = 200 for the image fields.

I don't know if there are any other options supported out of the box.

Anything that will not be recognized in the field render pipeline, will be added to the tag as an HTML attribute.