我正在混合使用 asp.net
网络表单和 asp.net-mvc
。要使用我包含的网络表单
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 就可以正常工作。
最佳答案
我刚刚完成了一个全新的示例项目并能够让它工作...我在项目的根目录中创建了一个名为 Reports 的文件夹,并在其中添加了 Billing.aspx 页面。然后我将下面的代码添加到 Home 文件夹中的默认索引 View ,如下所示。
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>
我的猜测是,即使您的表单的操作设置为 Billing.aspx,它也不会在正确的文件夹中查找它。尝试在 Billing.aspx 前面将“../../Reports/”添加到表单的操作中。由于 Billing 页面与 MVC 页面不在同一个根目录中,因此在发布操作时很可能不会去任何地方...
关于asp.net mvc javascript 回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1268746/