4

Not sure if I'm missing something obvious here, thought I'd post the question before I stop working on it hoping that someone can shed some light on the issue.

So I have the following in my razor template where Fields.Doc is a Component Link to a Component:

@using Tridion.ContentManager.ContentManagement;

@{
  var c = DoSomethingWithThisComponent(Fields.Doc);
}

@functions {
    public string DoSomethingWithThisComponent(Component component) {
        return component.BinaryContent.Filename;
    }
}

What I want to do is simply check the filename of a Binary if it exists, and then calculate it's filesize. I could have done this through a TBB but for the sake of a couple of lines of code I don't think this will be necessary.

So first of in my example above I is to return the title of the Binary Component (I know I haven't checked for nulls I'm just trying to test it out) before I go on to extend this how I need. I'm seeing the following error though when running this in Template Builder:

JScriptException: Expression 'RenderComponentPresentation()' had error 'The best overloaded method match for 'Tridion.Extensions.Mediators.Razor.Templating.Rzr25ca82c514914f49b0d50e54bcfbf9f6Template.DoSomethingWithThisComponent(Tridion.ContentManager.ContentManagement.Component)' has some invalid arguments'

Am I missing something really obvious here? Using Tridion 2011 SP1 HR1.

UPDATE

Thanks to Raj, I managed to use Tridion.Extensions.Mediators.Razor.Models and ComponentModel to access BinaryContent like so:

    @functions {
      public string DoSomethingWithThisComponent(Component component) {
        return component.TridionObject.BinaryContent.Filename;
      }
    }
2
  • try following. DoSomethingWithThisComponent(Models.ComponentModel component component),
    – Raj Kumar
    Commented Jul 12, 2014 at 21:35
  • 1
    Ibrar whats your end goal? Can't this be better achieved by creating a C# TBB?
    – user219
    Commented Jul 13, 2014 at 10:20

1 Answer 1

3

Use Models.ComponentModel instead of Component. check sample below

@functions {
    public string DoSomethingWithThisComponent(Models.ComponentModel component) {
        return component.Title;
    }
}
2
  • Thanks Raj. maybe I should have mentioned this but I need to access BinaryContent, can't seem to find any reference to this in ComponentModels, is this possible? I've updated my answer to add a bit more information. Commented Jul 13, 2014 at 9:10
  • Figured it out, I needed to use TridionObject. See update in my question. Commented Jul 13, 2014 at 10:28

Your Answer

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

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