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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for you answer, I was trying to do this as a last resort as I will have to wait for a request/postback.

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.