how does using HtmlHelper.BeginForm() work?

烂漫一生 提交于 2019-12-01 03:47:02

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!