views:

79

answers:

3

Ok, I have a master page which I include an ascx...

<%@ register tagname="header" tagprefix="vb" src="~/Views/Controls/Header/Header.ascx" %>

<vb:header id="pageHeader" runat="server" />

The ascx has a site map which uses the MvcSiteMapProvider...

<asp:SiteMapDataSource id="SiteMapDataSource1" sitemapprovider="Secure" showstartingnode="false" runat="server" />
<asp:menu id="headerMenu" DataSourceID="siteMap" orientation="Horizontal" staticenabledefaultpopoutimage="false" runat="server" IncludeStyleBlock="false"></asp:menu>        

Everything works nicely and then I needed to pass the model into the control so changed the master page to

html.RenderPartial("~/Views/Controls/Header/Header.ascx", Model)

Now I get a runtime error "Control '2_headerMenu' of type 'Menu' must be placed inside a form tag with runat=server." and Yes I do have a Form tag with runat=server in the master page.

Therefore does anyone know the render differences between these two approaches or any other pointers?? Thanks in advance.

A: 

Try to not use the relative path but just the name of the partial view

html.RenderPartial("Header", Model);

Now, another important point is to specify what kind of object you are using in your partial view. The first line should be:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<OBJECT-TYPE>" %>

Replace OBJECT-TYPE by the object type.

Lobsterm
A: 

Didn't think MVC will automatically find the ascx in that directory will it?

Yes pretty sure the Control is set up properly and loads OK until it tries to render the asp:menu

TJH7
A: 

The problem as one commentor noted is that you are mixing a WebForm control in an MVC view. As the error you are receiving states, the Menu has to be within the child control hierarchy of a <form runat="server"/> control. The MVC helpers such as Html.RenderPartial do not do anything with the control tree. Ideally you should not mix MVC and WebForms controls. It can work in certain situations but fails in others.

marcind