Html 在当前上下文中不存在。我可以使用 Web 视图语法在 Web 表单中使用 html class 吗?

Html does not exist in current context. Can I use html class in web forms using Web View syntax?

我正在编写一个应用程序,其中一些部分在 WebForms 中,一些部分在 MVC 中。我有一个 Webform.master 和一个 Site.Master。使用 Html class 时,我在 visual studio 中的 Webform.master 显示 "The name html does not exist in the current context." 但我在 site.master 文件中没有收到该错误,并且 html在那里被多次使用。

site.master 和 webform.master 都在 views/shared 目录中。

编辑:我的目的是在网络表单中呈现局部视图。我无法这样做,因为 html 在 webform.master 中无法识别。如果有其他方法来呈现局部视图,我会尽可能使用它。

这是Webform.master。

<%@ Master 
Language="C#" 
MasterPageFile="~/Views/Shared/Root.Master" 
AutoEventWireup="true" 
CodeBehind="Webform.master.cs" 
Inherits="JCIMS_MVC2_EF.WebUI.Views.Shared.Webform"
%>

<%@ Register src="SupportPartial.ascx" tagname="SupportPartial" tagprefix="uc1" %>

这是Site.master。

<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Root.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>


Html 方法都是 HtmlHelper class 的一部分,它是 MVC 的一个特性。

site.Master 的第一行告诉您的页面继承自 System.Web.Mvc.ViewMasterPage,这将使您能够访问 MVC 名称空间和您正在寻找的 HtmlHelper。

<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Root.Master" Inherits="System.Web.Mvc.ViewMasterPage" %>

您的 Webform.master 页面继承自 JCIMS_MVC2_EF.WebUI.Views.Shared.Webform,正如您从第一行看到的那样。所以你将无法在这里使用HtmlHelper。

<%@ Master 
Language="C#" 
MasterPageFile="~/Views/Shared/Root.Master" 
AutoEventWireup="true" 
CodeBehind="Webform.master.cs" 
Inherits="JCIMS_MVC2_EF.WebUI.Views.Shared.Webform"
%>