DotnetSparrow
DotnetSparrow

Reputation: 27996

helper method not printing anything

I have created a helper method in view like this:

@helper DisputeOpenedDays(DateTime createdDate)
    {

        TimeSpan difference = DateTime.Now.Subtract(createdDate);
        string.Format("0", difference.Days);
}

and when I use it in view like this

@DisputeOpenedDays(myobj.CreatedAt)

It doesnt print any thing

Upvotes: 0

Views: 134

Answers (2)

takepara
takepara

Reputation: 10443

@helper DisputeOpenedDays(DateTime createdDate)
{
 TimeSpan difference = DateTime.Now.Subtract(createdDate);
 @string.Format("{0}", difference.Days);
}

ASP.NET MVC 3 and the @helper syntax within Razor - ScottGu's Blog

Upvotes: 0

itsmatt
itsmatt

Reputation: 31416

Try:

string.Format("{0}", difference.Days);

The curly braces are missing.

Upvotes: 3

Related Questions