KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using Razor view with asp mvc preview 3 I am trying to create some methods which I would like available directly in the views. These are not really Html helper methods so I don't think extending HtmlHelper makes sense? my goal, be able to call methods in the view i.e. @HelloWorld(); vs @Html.HelloWorld() I can get Html.HelloWorld to work by creating an extension method on HtmlHelper public static class HtmlExtensions { public static string HelloWorld(this HtmlHelper helper) { return "Hello"; } } I would like to do the same thing but for the view; my problem - what type of object is the view? Note: I was able to get this to work by defining the methods in the .cshtml page @functions { public string HelloWorld() { return "Hello"; } } @HelloWorld() @* now this works *@ then I tried to put this code my _viewstart.cshtml file thinking it would be available in all views but it was not if I knew which type the view was I think it could be easily extended, any help appreciated
Tags (comma-separated)
Save Edits
Cancel