0

I've created a asp:TreeView control in a ASP.NET MVC Partial View. The view renders fine without the control. With the control I get the follow exception:

Control 'MainContent_TreeView1' of type 'TreeView' must be placed inside a form tag with runat=server

Since this is not a WebForms project, I don't see why I'd need a form. What am I missing?

Nilzor
  • 18,082
  • 22
  • 100
  • 167
  • Note: Creating a dummy form wrapper allows me to use the control. I just have to be careful with how I use the other WinForms-related functions, like postbacks, when using it in an MVC-page. – Nilzor Feb 21 '12 at 12:37

1 Answers1

1

Basically, I don't believe you can add webforms controls to MVC pages.

You need to create a separate aspx page (a webforms page inside your MVC project) to use server controls.

Things I cannot do in ASP.NET MVC

Community
  • 1
  • 1
James Osborn
  • 1,275
  • 7
  • 12
  • also, more importantly, why would you want to.. webforms controls always add some overhead. the point of mvc is to return lightweight views in as simple as possible html with the logic taking place in the layers behind the view – spaceman Feb 21 '12 at 14:12