我讨厌那些剃须刀帮手。(LabelFor,TextboxFor ...)他们试图帮助我,但他们什么也没教我。
我想尝试使用 ASPX 引擎。当我打开它时,左侧甚至还有工具箱,里面有所有旧的好 html 命令。为什么我不能使用它?
当我知道 MVC 不需要它时,为什么当我尝试构建应用程序智能感知时说 runat="server" 是必需的?
简而言之,如何使用 helpers 编写不带 HTML 的 HTML?任何建设性的建议将不胜感激。
样本:
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">Home Page</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:ListBox runat="server">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:ListBox>
</asp:Content>
错误:
`Server Error in '/' Application.
Control 'MainContent_ctl00' of type 'ListBox' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control 'MainContent_ctl00' of type 'ListBox' must be placed inside a form tag with runat=server.
Source Error:
Line 22: <ul id="menu">
Line 23: <li><%: Html.ActionLink("Home", "Index", "Home")%></li>
Line 24: <li><%: Html.ActionLink("About", "About", "Home")%></li>
Line 25: </ul>
Line 26: </div>`