Hi, I have a question about how to do this in the best way:
I have a method GET
in my controller
that receives 3 parameters:
[Route("api/Visita/{idCompania}/{idLocal}/{fecha}")]
public Visita Get(short idCompania, short idLocal, string fecha)
In my view I have these parameters available in my ViewBag
, is there a clean way to pass them as parameters to $.getJSON
so that it takes care of executing the call to my asp.net-web-api method ?
should I locate you in how hidden
to obtain them through $("#idLocal").val()
for example?
I can only interact with objects from the DOM
?
If the data is in the ViewBag and is not going to change, you could assign it to variables that the json builds.
As you can see, you create the json that you would send as data from $.getJSON
If the client code is in a separate .js in the view you define the lines
then inside the .js you just access the variables since these are global
You don't need to use hidden fields, you could use the browser URL to get them (since they are available in the route):
Of course this is a javascript only solution .