Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

When using the default siteEditField function

@Html.SiteEditField(Model.Component, Model.Component.Fields["Heading"])

And the field does not exist in the broker it generates an exception, that the field does not exist. What I expected was that the method

public static MvcHtmlString SiteEditField(this HtmlHelper helper, IComponent component, IField field, int index)

Would validate the input of value, if the field is empty or none existing to generate the siteedit tags for empty field.

How can this best be achieved; Extending the SiteEditHelper is not allowed since its a sealed class.

share|improve this question
    
which version of DD4T are you using? –  Bart Koopman Sep 4 at 15:29

1 Answer 1

You could create your own SiteEdit Extension methods helper which wrap the DD4T one e.g.

 public static class MySiteEditHelpers
 {
      public static MvcHtmlString SafeSiteEditField(this HtmlHelper helper, IComponent component, IField field)
      {
           if(field != null)
              return helper.SiteEditField(...)
           return new MvcHtmlString(string.Empty);
      }
 }

(Alternatively || Additionally) you could raise this as an issue on the DD4T GitHub, fork the repo, fix it, and submit a pull request for the next release!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.