What are the consideration while writing the Helper extension methods in .cshtml vs .cs files.
One advantage I see while writing in .cs files is when the view engine changes we don’t have to rewrite the Helpers again.
Apart from this are there any advantage over the other?
Another advantage of helpers in .cs is that they are unit testable and that’s what sells them best to me. Of course the fact that they are portable across different view engines is a great benefit as well. For example I have new ASP.NET MVC 3 Razor applications but which still use some legacy WebForms views from ASP.NET MVC 2 applications. So my new helpers in .cs files work perfectly fine in both views.
You could Razor view embedded
@helperfor some very small and isolated peace of HTML that will never leave the boundaries of the given view. For everything else use real helpers, editor/display templates, partials, …To be honest with you, I’ve absolutely never used
@helperin any of my codebases and I cannot say that I am missing some functionality.