1

I am programming an app that has some sections in WebForms and some in MVC. I have a Webform.master and a Site.Master. When using the Html class, My Webform.master in visual studio says "The name html does not exist in the current context." but I don't get that error in site.master file, and html is used many times there.

Both the site.master and webform.master are in the views/shared directory.

EDIT: my purpose is to render a partial view in webforms. I'm unable to do that because html is not recognized in webform.master. If there's an alternate way to render a partial view, I'd use that if possible.

This is the 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" %>

This is the Site.master.

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


0

1 Answer 1

1

The Html methods are all part of the HtmlHelper class which is a feature of MVC.

The first line of site.Master is telling your page to inherit from System.Web.Mvc.ViewMasterPage which will give you access to the MVC namespace and the HtmlHelper you're looking for.

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

Your Webform.master page inherits from JCIMS_MVC2_EF.WebUI.Views.Shared.Webform as you can see from the first line. So you will not be able to use the HtmlHelper here.

<%@ Master 
Language="C#" 
MasterPageFile="~/Views/Shared/Root.Master" 
AutoEventWireup="true" 
CodeBehind="Webform.master.cs" 
Inherits="JCIMS_MVC2_EF.WebUI.Views.Shared.Webform"
%>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer, and I apologize, but I forgot to mention my main goal in the question. I am trying to render a partial view. But as you've shown, the Html helper isn't accessible to the webform.master class. Since I cannot use the helper, is there another way I can render the partial?
Most direct method to bypass the block would be to use jQuery's .load() function to load it via an HTTP request; you could also use a vanilla JS method to do something similar if you don't have/want jQuery in your project. If you're set on using the HtmlHelper you could try creating your own HtmlHelper since it has a few public constructors, but that may be more challenging than it's worth. See this question for a few possibilities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.