0

I have a solution containing an ASP.NET WebForms Website and a MVC 5 Application. The WebForms project contains a MenuControl for main navigation. I need to have the same menu in the MVC Project as well.

I tried to get the html of the menu using the solution mentioned at https://stackoverflow.com/a/58931/1300140 without any success. It is throwing an error saying "Control 'ctl03' of type 'Menu' must be placed inside a form tag with runat=server"

How can I get the HTML output of the Menu? Also, is there any better way to achieve what I am trying to do?

Community
  • 1
  • 1
Libin TK
  • 1,477
  • 2
  • 25
  • 46

1 Answers1

1

First create a div (or any other asp.net control) with tag runat=server so you can reach it from code behind.

then a little jquery and done.

html:

 <div id="myDiv" runat="server"></div>

jquery:

$(document).ready(function () {
       $("myDiv").html($("#yourMenuIdHere").html());
    });

code behind:

var divContent= myDiv.InnerHtml;

so you got everything in divContent variable. you can hide your myDiv on pageload if you want. let me know if this helps.

Badiparmagi
  • 1,285
  • 1
  • 14
  • 24
  • 1
    Thanks for you answer, I was trying to do this as a last resort as I will have to wait for a request/postback. – Libin TK Oct 13 '16 at 08:22