1
I’m having trouble assembling a URL with parameters.
Until then I managed using the @Url.Action
, but the second parameter dataPesquisa
is going nil.
I imagine when the parameter passed directly to the @Url.Action
C# should perform some conversion and in case I am using the replace
to be able to give values to the parameters.
Note: I have already checked the variable data
and it’s coming with value, it’s only going null when it runs my Action.
Way I did:
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");
}
"the dataPesquisa parameter is not going right". What does that mean?
– Jéf Bueno
No, I just posted my action
– Nicola Bogar
"No" what? I asked what that means.
– Jéf Bueno
@LINQ, sorry, I edited my question, I think it’s now clearer.
– Nicola Bogar
Checks whether the variable
conta
has some value when calling that script there.– Jéf Bueno
I already checked, in my action when called the account has value, but the dataPesquisa comes null, I will post my variable url to check how it is getting.
– Nicola Bogar
@LINQ, take a look
– Nicola Bogar
How do you plan to use a bar date if bar is just a "reserved character" in URL’s?
– Jéf Bueno
So, I figured that would be the problem, but my question is, how to pass parameters to the Url.Action with jquery variables, because I imagine that putting the data parameter, c# does the conversion, you know ? so much so that I used these parameters in $.getJson calls and it worked. Now that I’m using with the Url.Action I’m having trouble.
– Nicola Bogar
There’s no way you can do that. Url.Action is Razor code, it will run on server, the Javascript code runs on the client. You may notice this by opening the code on your page, in the script part there will be no Url.Action, there will be only the value returned by this function. This is because it has already been executed on the server.
– Jéf Bueno
@LINQ, do you know if there’s any other way I can call my action and open it in a new window the way I’m doing it ?
– Nicola Bogar
There are a million ways. Why don’t you just change the date format before making the request? Make your URL look like this
dataPesquisa=31-12-2009
.– Jéf Bueno
For what format for example? could give me a horizon, rsrs.
– Nicola Bogar
Dude, I wrote the format in the comment.
– Jéf Bueno
I put it the way you said it and keep going null the parameter :/
– Nicola Bogar