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;
}
}