ASP.Net MVC3 - Pass razor markup as a parameter

后端 未结 4 1601
予麋鹿
予麋鹿 2020-12-30 00:38

I have a helper called EditableArea which provides a user with a runtime-editable div (via JS). EditableArea helper checks if an editable area (not

4条回答
  •  暖寄归人
    2020-12-30 01:30

    Taking this further, it is possible to pass the markup directly to a helper, without an extension method.

    @helper HelperWithChild(Func renderChild)
    {
        
    @renderChild(this)
    } @HelperWithChild(@

    Hello

    )

    For multi-line markup is required as well:

    @HelperWithChild(@
        @AnotherHelper()
    
        

    With more markup

    ) @helper AnotherHelper() {

    Another helper

    }

    Though I'm not sure how this will play out with Model - my helpers only use their parameters.

提交回复
热议问题