2009-08-12 4 views
1

나는 asp.net webforms 및 asp.net mvc를 혼합합니다. 포함 된 웹 양식을 사용하려면asp.net mvc javascript postback

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

public static void RegisterRoutes (RouteCollection routes) 메소드에서.

잘 작동하는 것 같습니다. 그러나 asp.net 웹 폼 페이지의 자바 스크립트 포스트 백이 작동하지 않습니다. 구체적으로

<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 페이지를 추가했습니다. 그런 다음 아래와 같이 홈 폴더 내의 기본 인덱스보기에 아래 코드를 추가했습니다. 홈 \ 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> 


내 생각 엔 \

Global.asax에

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

MVC 페이지 뷰는 양식의 조치를 청구로 설정된 경우에도 것입니다. aspx, 올바른 폴더에서 찾고 있지 않습니다. Billing.aspx 앞에 "../../Reports/"를 양식의 작업에 추가하십시오. Billing 페이지가 MVC 페이지와 같은 루트에 있지 않으므로 게시 작업의 어느 곳으로도 갈 수 없습니다.

+0

포함했습니다. // 웹 양식 파일을 무시하십시오. routes.IgnoreRoute ("{resource} .axd/{* pathInfo}"); routes.IgnoreRoute ("{resource} .aspx/{* pathInfo}"); 및 routes.IgnoreRoute ("Billing.aspx/{* pathInfo}"); 문제를 해결하지 못했습니다. – bjwbell