I'm having trouble setting up a URL with parameters.
Until then I have been using @Url.Action
, but the second parameter dataPesquisa
is going null.
I imagine that when the parameter passed directly to @Url.Action
C # should perform some conversion and in the case I'm using replace
to be able to give values to the parameters.
Note: I already checked the variable data
and it is coming with value, it is only going null when executing my Action.
How I did it:
var conta = $('#selectContaCorrente').val();
dataParaPesquisa = dataFormatada(dataPesquisa.val());
var url = '@Url.Action("ExtratoPrint", "Extrato", new { contaCorrente = "paramContaCorrente", dataPesquisa = "paramDataPesquisa" })';
url = url.replace('paramContaCorrente', conta);
url = url.replace('paramDataPesquisa', dataPesquisa.val());
window.open(url, "_blank");
Variable value url
: /Extrato/ExtratoPrint?contaCorrente=3cb012d1-6ceb-436f-8a0f-22c713703804&dataPesquisa=31/12/2009
Action
public ActionResult ExtratoPrint(string contaCorrente, string dataPesquisa)
{
ViewBag.ContaCorrente = contaCorrente;
ViewBag.DataPesquisa = dataPesquisa;
return View("ExtratoPrint");
}