5

I have some links within Rich Text which are not resolving. I found the ResolveRichText() extension method, but how can I use these extension methods in our views?

In the below code sub_copy is my Rich Text field which consist of links:

@Model.Component.Fields["sub_copy"].ResolveRichText()

Do I need to add any namespace for this?

I'm getting the following compilation error:

CS1061: 'string' does not contain a definition for 'ResolveRichText' and no extension method 'ResolveRichText' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

  • What is the error you are getting when you use the ResolveRichText() extension method? – Bart Koopman Jul 31 '13 at 7:28
  • I am getting compilation error : CS1061: 'string' does not contain a definition for 'ResolveRichText' and no extension method 'ResolveRichText' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) – roop Jul 31 '13 at 10:15
  • Do you have the following using in your view?: @using DD4T.Mvc.Html – Albert Romkes Jul 31 '13 at 11:54
  • And you should be using @Model.Component.Fields["sub_copy"].Value.ResolveRichText() – Albert Romkes Jul 31 '13 at 12:01
  • I have added @using DD4T.Mvc.Html.Also i tried @Model.Component.Fields["sub_copy"].Value.ResolveRichText() ,giving me the same compilation error message – roop Jul 31 '13 at 12:41
4

DD4T comes with a couple of helper methods, which you can integrate in your own DD4T project. You can find the class here.

Depending on where you put the class, you will possibly need to add a using directive in your Views.

| improve this answer | |
  • The class in your link has no extensions methods. Notice the difference with this method signature: public static MvcHtmlString ResolveRichText(this string value) – Raimond Jul 31 '13 at 13:08
  • I have created a class and added in my view. I m using the code code. In my view,i have used as var htmlhelper= new HtmlHelperText() @htmlhelper.ResolveRichText(@Model.Component.Fields["sub_copy"].Value).its resolving the links in the richtextfield.But if i am using the same code for any other embedded RTF fields its giving me compilation error of-System.nullrefrence exception:object refrence not set to an instance of an object. The code is not working for embedded RTF fields – roop Jul 31 '13 at 13:09
  • Time to use a debugger for that. ;) – Raimond Jul 31 '13 at 13:10
  • @Roop - I'm 99% sure we've used the function with embedded fields, could you paste your xml and code into your question? – johnwinter Jul 31 '13 at 17:59
  • @Raimond yes you were right,I changed my method signature to public static MvcHtmlString ResolveRichText().It worked for me.But one thing ,i noticed this issue is only with the embedded richtext fields not with normal richtext fields – roop Aug 2 '13 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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