Reputation: 347
I have a project that I have been creating and I publish it in the IIS, there everything is fine, I can visualize my Crystal Reports reports.
Now I have re-published the project (update in IIS), but I can not see my Crystal Reports reports that I call from js.
var url = "/ReporteIngresoVP/RPVistaPreviaIngreso";
window.open(url, "_blank");
At the time of calling it, it opens a new tab (as it should be) and shows me a 404:
When I open another report (from the controller) it shows me the correct path
(everything from IIS):
As I read out there if I need to use urls that point to asp.net MVC elements from js, they should go with the @Url.Action
so I am trying the following:
var url2='@Url.Action("RPVistaPreviaIngreso","CustomerReporteIngresoVP")';
window.open(url2, "_blank");
But when I navigate, I get the URL in this way:
How can I complete the route or can I go to the view/controller what I want in both case, Visual Studio and the project published using javascript?
UPDATE
I try to navigate from a click function, I never pass any url, what can I modify?
$('.vpBTN').click(function () {
//OTHER DATA
$.ajax({
url: "setDatosIngreso",
method: "POST",
data: {
factura: datoFactura,
poliza: datosPoliza,
fecha: datosFecha,
via: datosVia,
bruto: datosBruto,
neto: datosNeto,
bultos: datosBultos
},
async: false,
//dataType: "json",
success: function (respuesta) {
var url = "IKOR/ReporteIngresoVP/RPVistaPreviaIngreso";
window.open(url2, "_blank");
}
});
});
Upvotes: 1
Views: 3688
Reputation: 347
What I did to solve it and can help someone:
Create a div
that has nothing, just with a clas
s and data-request-ur
l in this last I send my @Url.Action()
<div class="urlPasar" data-request-url="@Url.Action("RPVistaPreviaIngreso","ReporteIngresoVP")"></div>
In JS capture the value of the data
that is in the div
var url = $('.urlPasar').data('request-url');
window.open(url, "_blank");
Works for both in Visual Studio and in a published project
Upvotes: 2
Reputation: 24957
The problem is you're using external JS file which included inside Razor view, and obviously you cannot use Razor HTML helpers to render complete URL inside JS file. You need to pass the URL as JS function parameter instead:
External JS
// create this function to redirect
function redirectToUrl(url)
{
window.open(url, "_blank");
}
Razor view (<script>
tag)
$('.vpBTN').click(function () {
// other data
$.ajax({
url: "setDatosIngreso",
method: "POST",
data: {
factura: datoFactura,
poliza: datosPoliza,
fecha: datosFecha,
via: datosVia,
bruto: datosBruto,
neto: datosNeto,
bultos: datosBultos
},
success: function (respuesta) {
var url = '@Url.Action("RPVistaPreviaIngreso","CustomerReporteIngresoVP")';
redirectToUrl(url);
}
});
});
Upvotes: 1