如何在MVC中引用URL内容

时间:2013-06-06 03:11:24

标签: jquery asp.net-mvc razor

我有下面的链接工作正常,但我只是想使用Url.Content请指教,谢谢

 $('#btnAddConsumer').click(function () {
        window.open('/ProductDetails/AddNewProduct/', 'AddProduct', 'height=' + (window.screen.height - 470) + ',width=820,left=' + (window.screen.width - 5) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
    });

2 个答案:

答案 0 :(得分:0)

尝试以下代码

$('#btnAddConsumer').click(function () {
        window.open('@Url.Content("~/ProductDetails/AddNewProduct/")', 'AddProduct', 'height=' + (window.screen.height - 470) + ',width=820,left=' + (window.screen.width - 5) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
    });

答案 1 :(得分:0)

我认为你需要UrlHelper的Action方法:

'#btnAddConsumer').click(function () {
        window.open('@Url.Action("AddNewProduct", "ProductDetails")', 'AddProduct', 'height=' + (window.screen.height - 470) + ',width=820,left=' + (window.screen.width - 5) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
    });