Adding a custom HTML Helper to MVC Project

前端 未结 2 2021
独厮守ぢ
独厮守ぢ 2020-12-30 14:49

I\'ve been browsing the web trying to find a good example/tutorial detailing how I can create and use my own custom HTML Helpers for my MVC 3 Razor application I found this

2条回答
  •  悲&欢浪女
    2020-12-30 15:45

    I think an easier option would be to do the following: 1. Create a view as usual, place your helpers in that as usual with the mix of code and html as you like. 2. Move the view to the App_Code folder. 3. Get to your helps in all your views as so (Note that _MyHelpers is the name of the view in the App_Code folder):

    @_MyHelpers.JQMRadioTrueFalse("Voice Mail on your Home Phone?", "HomePhoneHasAnswerPhone", Model.TrueFalse, t.HomePhoneHasAnswerPhone)
    

    This would be an example of a view in the App_Code folder that is accessed on any view as above:

        @helper JQMRadioList(string Legend, string RadioListName, List options, bool Horizontal = false, string CurrentSelection = "")
        {
            
    @Legend: @foreach (var li in options) { @JQMRadioListItem(RadioListName, li.TheValue, li.Text, CurrentSelection) }
    }

提交回复
热议问题