views:

340

answers:

1

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.

+1  A: 

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...

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