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?)

5
  • What is the error you are getting when you use the ResolveRichText() extension method? Jul 31, 2013 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, 2013 at 10:15
  • Do you have the following using in your view?: @using DD4T.Mvc.Html Jul 31, 2013 at 11:54
  • And you should be using @Model.Component.Fields["sub_copy"].Value.ResolveRichText() Jul 31, 2013 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, 2013 at 12:41

1 Answer 1

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.

6
  • 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, 2013 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, 2013 at 13:09
  • Time to use a debugger for that. ;)
    – Raimond
    Jul 31, 2013 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, 2013 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, 2013 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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