gpt4 book ai didi

asp.net - 为什么不能有一个包含多个服务器端 Form 标签的页面?

转载 作者:行者123 更新时间:2023-12-03 21:40:17 26 4
gpt4 key购买 nike

我想知道为什么 asp.net 不允许这样做?许多页面包含不止一种表单,登录 - 注册表单,搜索 - 其他表单等等...

所以我的猜测是我可以将一种形式与精细的 oop asp.net 对象相关联,将另一种形式与纯 html 相关联,并且我必须以两种完全独立的方式处理来自这些来源的响应。是吗?

请解释这里发生了什么,以及为什么 asp.net 不允许这样做

最佳答案

ASP.NET 网络表单依赖于单一的服务器端表单。

您可以根据需要添加任意数量的客户端表单(没有runat="server" 属性)。


这是由于尝试为 Web 开发提供类似桌面的开发模型。

参见 this更多原因的 MSDN 杂志文章:

The single-form model is a key element for the implementation of the ASP.NET state maintenance feature. Since the page always posts to itself, the runtime finds it easy to retrieve and restore the state saved during the last access. While there are other ways to save and restore the state of a page, using a single-form model is by far the simplest and most effective of all solutions.

In general, renouncing multiple forms is not a big sacrifice. Multiple forms are sometimes useful, but probably not as frequently as you may think. A scenario in which you would find it helpful to use multiple forms is when you implement form-based functionality in a large number of pages—in search and login dialogs, for example. I'll return to this later in the column. Before going any further, though, a review of the HtmlForm class is in order.


注意:

ASP.NET-MVC 没有这样的限制——你可以有任意多的表单。

关于asp.net - 为什么不能有一个包含多个服务器端 Form 标签的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4360270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com