2009-08-12 14 views
1

私はasp.net webformsとasp.net mvcを混在させています。私が含まれているウェブフォームを使用するにはasp.net mvc javascriptポストバック

routes.IgnoreRoute( "Reports/{* 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

+0

Billing.aspxは現在のページ – bjwbell

+0

私は自分の答えを更新しました... – RSolberg

答えて

2

私はちょうど新しいサンプルプロジェクトを完了し、これを動作させることができました...私はReportsという名前の私のプロジェクトのルートにフォルダを作成し、そこでBilling.aspxページを追加しました。次に、下のコードをホームフォルダ内のデフォルトのインデックスビューに追加しました。私の推測では、フォームのアクションが課金に設定されているにもかかわらず、ということである

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

私は含めました // webformsファイルを無視します routes.IgnoreRoute( "{resource} .axd/{* pathInfo}"); routes.IgnoreRoute( "{resource} .aspx/{* pathInfo}"); および routes.IgnoreRoute( "Billing.aspx/{* pathInfo}"); 問題を修正しませんでした – bjwbell

関連する問題