how I can create something like this: Html.MyApp.ActionLink()?
Thanks.
how I can create something like this: Html.MyApp.ActionLink()? Thanks.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t do this. The only way you can add to the Html class is via an extension method. You cannot add "Extension Properties", which is what would be required for you to use
Html.MyApp. The closest you could come isHtml.MyApp().Method(...)Your best bet is probably to either include them as extension methods on Html, or create a new class completely (eg.
MyAppHtml.Method(...)orMyApp.Html.Method(...)). There was a blog post around recently specifically showing an "Html5" class with these methods, but unfortunately my Google skills are failing me, and I can’t find it 🙁Added 13 Oct 2011 as asked in comment
To do something like
Html.MyApp().ActionLink()you need to create an extension method onHtmlHelper, that returns an instance of a class with your custom method:Note: You’ll need to import the namespace this class is in in
Web.config, like this:The change in the Web.Config file needs to be done in the config file for the view, not the global one