williamsandonz
williamsandonz

Reputation: 16430

Is there a performance sacrifice when calling a C# helper from razor?

If I (from my Razor view), call a c# Helper (I.E compiled into a DLL). Is there a performance loss here?

E.G

I could use @Model.User.GetFriendlyName(); (calls method in my Model inside DLL).

Or I could pass the friendlyname into the Razor view, (storing in the viewmodel initially).

Is there a speed difference between these two methodologies?

Upvotes: 3

Views: 202

Answers (1)

Mike Koder
Mike Koder

Reputation: 1928

Calling User.GetFriendlyName() isn't any slower in the view than anywhere else. Razor views are compiled into classes behind the scenes.

One thing to keep in mind is that if that method gets something from the database that would cause extra queries and if using orm with lazy loading the context/session could be lost by then.

Upvotes: 1

Related Questions