Umbraco razor template - Get a formatted date from the field specified in the parameter

I am trying to return a formatted date from a razor template to umbraco. I am not sure how to get the value from the field defined in the parameter.

Here is the code I'm playing with. The field I am passing is called "articleDate". I get the output of the parameter value, however, when I try to get the field value using the parameter name, it does not return anything. If I ask for a value by the field name, this works. How to create a common macro like this?

@{var param = @Parameter.dateField;}
Field Name: @param
<br/>
Field Value: @Model.param
<br/>    
Field Value: @Model.articleDate

I also tried using @ Model.GetDynamicMember (..), but that just throws an exception.

Field Value: @Model.GetDynamicMember("articleDate");​

Error loading Razor Script getDate.cshtml
Cannot invoke a non-delegate type

Can someone point me in the right direction? I'm just trying to create a simple macro that I can use to format dates on my page.

? :

<umbraco:Macro ID="Macro1" Alias="getDate" dateField="articleDate" runat="server"></umbraco:Macro>
+3
1

, :

<umbraco:Macro ID="Macro1" Alias="getDate" dateField="articleDate" runat="server"></umbraco:Macro>

"articleDate". Model articleDate, :

Field Value: @Model.getProperty(Parameter.dateField).Value

- - RenderPage. : http://joeriks.wordpress.com/2011/03/11/better-structure-for-your-razor-scripts-with-renderpage-in-umbraco/

:

@helper GetDate(dynamic dateField)
{
     @dateField.ToString("[yourFormat]")
}

, RenderPage, Page:

<umbraco:macro language="razor" runat="server">
@{
    Page.dateField=Model.articleDate;
}
@RenderPage("~/macroscripts/getdate.cshtml")
</umbraco:macro>

getdate.cshtml:

@Page.datefield.ToString("[yourFormat]")
+6

All Articles