how does using HtmlHelper.BeginForm() work?

前端 未结 2 1365
深忆病人
深忆病人 2021-01-12 06:35

Ok so I want to know how

<% using (Html.BeginForm()) { %>
  
<% } %>

produce



        
相关标签:
2条回答
  • 2021-01-12 07:29

    Much like SLaks said, it generates a finally block that calls the EndForm which calls the Dispose method on the IDisposable interface that the object .BeginForm() returns.

    BeginForm uses Rseponse.Write to write out the HTML to the response.

    EndForm writes out the closing tag to the Response. Thusly anything that happens in between the constructor returned from BeginForm and the Dispose method will be written to the response properly between the form tags.

    0 讨论(0)
  • 2021-01-12 07:36

    BeginForm returns an IDisposable which calls EndForm in Dispose.

    When you write using(Html.BeginForm()) { ... }, the compiler generates a finally block that calls Dispose, which in turn calls EndForm and closes the <form> tag.

    You can duplicate this effect by writing your own class that implements IDisposable.

    0 讨论(0)
提交回复
热议问题