So essentially, I'm building a web API, and I'm trying to use ajax to query a web service that accepts two arguments. I need to pass a List of Stings (SSNs) and I need to pass a single string to determine which environment it queries. ("a" for acceptance, and "i" for integration).
I'm using cshtml with razor. And so far this section is successfully giving me what I want from the divs.
var pInputSssns = document.GetElementById(“SSNinput”).value;
var pTestRegion = document.GetElementById(“testRegion’).value;
However, just beneath it. I'm trying to insert both these params into an ajax call.
$.ajax({
type: 'GET',
contentType: "application/json; charset=utf-8"
url: "myurl",
data:"{}",
success: function (data) {
// populate a table
}
});
I've heard multiple opinions on how that can be done. Can I serialize them both as JSON, and then put two JSON objects in the data parameter? I've also heard that I can pass a c-sharp object, but if I try and do that I can't access the html variable while I'm inside the Razor code.
@{ AjaxParam ap = new AjaxParam(); ap.pInputSsns = pInputSsns;}
Is there a good way to pass both of them in there? For reference, here's the Controller:
[ScriptMethod (ResponseFormat = Response Format.Json)]
[System.Web.Http.HttpGet]
public JArray GetSSNAssociations([FromUri] List <string> pInputSsns, string pTestRegion)
{
\\ do something
}
Appreciate it everyone.