2

I'm mixing asp.net webforms and asp.net-mvc. To use webforms I've included

routes.IgnoreRoute("Reports/{*pathInfo}");

in the public static void RegisterRoutes(RouteCollection routes) method.

It seems to work just fine. But javascript postbacks on the asp.net webform pages don't work. Specifically

<script type="text/javascript">
function callMethod(methodName, methodArgument)

{

        alert('test1');

        document.getElementById("methodname").value=methodName;

        document.getElementById("methodargument").value=methodArgument;         

alert('test2');

document.forms[0].submit();

    }

</script>

doesn't work. Everything is fine until the document.forms[0].submit(); call which appears to do nothing. If I completely disable the asp.net MVC route mapping then the above Javascript works just fine.

3
  • What's the value of the action attribute on the first form tag? Commented Aug 12, 2009 at 21:16
  • <form method="post" action="Billing.aspx?tenantId=0003-0140&amp;rentNum=0" id="ctl00_ctl00_basemasterform"> Billing.aspx is the current page Commented Aug 12, 2009 at 21:22
  • I updated my answer for you... Commented Aug 12, 2009 at 21:36

1 Answer 1

2

I just completed a brand new sample project and was able to get this to work... I created a folder in the root of my project called Reports and added the Billing.aspx page there. I then added the code below to the default Index view within the Home folder as shown below.

Global.asax

routes.IgnoreRoute("Reports/{*pathInfo}");

MVC Page Views\Home\Index.aspx

<form method="post" action="../../Reports/Billing.aspx?tenantId=0003-0140&rentNum=0" id="myForm"> 
    <input type="text" id="sample" /><br />
    <input type="button" onclick="callMethod();" value="send" />
</form>
<script type="text/javascript">
    function callMethod()
    {
        alert('test1');
        alert(document.getElementById("sample").value);
        alert('test2');
        document.forms[0].submit();
    }
</script>


My guess is that even though your form's action is set to Billing.aspx, it is not looking for it in the correct folder. Try adding "../../Reports/" in front of Billing.aspx to your form's action. Since the Billing page is not in the same root as the MVC page, that is likely to not go anywhere on a post action...

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

1 Comment

I've included //ignore webforms files routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); and routes.IgnoreRoute("Billing.aspx/{*pathInfo}"); and it didn't fix the issue

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.