2009-08-12 94 views
1

我在混合asp.net webforms和asp.net mvc。要使用的WebForms我包括asp.net mvc javascript postback

routes.IgnoreRoute( 「報告/ {*} PATHINFO」);

public static void RegisterRoutes(RouteCollection routes)方法。

它似乎工作得很好。但在asp.net webform頁面上的javascript回發不起作用。特別是

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

不起作用。一切都很好,直到「document.forms [0] .submit();」看起來什麼都不做的電話。如果我完全禁用了asp.net MVC路由映射,那麼上面的Javascript工作得很好。

+0

第一個表單標記上的action屬性的值是多少? – ZippyV 2009-08-12 21:16:15

+0

Billing.aspx是當前頁面 – bjwbell 2009-08-12 21:22:26

+0

我爲您更新了我的答案...... – RSolberg 2009-08-12 21:36:40

回答

2

我剛剛完成了一個全新的樣本項目,並能夠得到這個工作。我在我的項目被稱爲報表的根目錄中創建一個文件夾,並添加了Billing.aspx頁面出現。然後,我將下面的代碼添加到Home文件夾中的默認Index視圖,如下所示。

的Global.asax

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

MVC頁面訪問量\首頁\ 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> 


我的猜測是,即使表單的動作爲結算。 aspx,它沒有在正確的文件夾中查找它。嘗試將Billing.aspx前面的「../../Reports/」添加到表單的操作中。由於「結算」頁面與MVC頁面不在同一個根目錄,因此很可能無法在後續操作中的任何位置執行...

+0

我已經包括 //忽略web表單文件 routes.IgnoreRoute( 「{}資源個.axd/{*} PATHINFO」); routes.IgnoreRoute(「{resource} .aspx/{* pathInfo}」); 和 routes.IgnoreRoute( 「Billing.aspx/{*} PATHINFO」); 並沒有解決問題 – bjwbell 2009-08-12 21:29:59