Pass jquery parameters to Url.Action ASP.NET MVC [closed]

1

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");
}
    
asked by anonymous 31.10.2017 / 16:37

2 answers

3

I solved my problem using @ Html.Raw, as follows:

var url = '@Html.Raw(@Url.Action("ExtratoPrint", "Extrato", new { contaCorrente = "paramContaCorrente", dataPesquisa = "paramDataPesquisa" }))';
    
31.10.2017 / 17:28
0

You can concatenate the values, something like this:

var conta = "3cb012d1-6ceb-436f-8a0f-22c713703804";
var dataPesquisa = "31/12/2009";
var url = '@Url.Action("ExtratoPrint", "Extrato")?contaCorrente=' + conta + '&dataPesquisa=' + dataPesquisa;

The result will be this:

/extrato/extratoprint?contaCorrente=3cb012d1-6ceb-436f-8a0f-22c713703804&dataPesquisa=31/12/2009
    
31.10.2017 / 17:26