Custom html helpers: Create helper with “using” statement support

后端 未结 3 1638
长情又很酷
长情又很酷 2020-12-07 16:28

I\'m writing my first asp.net mvc application and I have a question about custom Html helpers:

For making a form, you can use:

<% using (Html.Begi         


        
3条回答
  •  半阙折子戏
    2020-12-07 16:54

    I tried following the advice given here in MVC3, but I ran into trouble using:

    htmlHelper.ViewContext.HttpContext.Response.Write(...);
    

    When I used this code, my helper was writing into the Response stream BEFORE my Layout was rendered. This didn't work well.

    Instead I used this:

    htmlHelper.ViewContext.Writer.Write(...);
    

提交回复
热议问题