Note that there are some explanatory texts on larger screens.

plurals
  1. POParameter in web api method call is coming in null
    primarykey
    data
    text
    <p>Writing a web api project and one of the parameters (which is a json array) on my method is coming into the api null. The jquery I'm making the call with looks like this:</p> <pre><code>&lt;script&gt; $(document).ready(function () { $('#btnSubmit').click(function () { var jsRequestAction = { appId: 'appName', custId: 'custId', oprId: 'oprId', businessProcess: 'Requisition', action: 'Approve', actionKeys: [ 'blah blah 1', 'blah blah 2', 'blah blah 3' ] }; $.ajax({ type: "POST", content: "json", url: "http://localhost/api/appName/custId/oprId", contentType: "application/json; charset=utf-8", data: JSON.stringify({ requestAction: jsRequestAction }) }); }); }); &lt;/script&gt; </code></pre> <p>My web api method looks like this:</p> <pre><code>public IList&lt;ResponseAction&gt; ActionCounter(string appName, string custCode, string custUserName, RequestAction requestAction) { IList&lt;ResponseAction&gt; actionResponseList = new List&lt;ResponseAction&gt;(); var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); conn.Open(); try { foreach (string s in requestAction.actionKeys) { var command = new SqlCommand { CommandText = "Sql statement", Connection = conn }; command.ExecuteNonQuery(); var reply = new ResponseAction(); reply.responseActionKey = s; reply.responseMessage = "Success"; actionResponseList.Add(reply); } return actionResponseList; } finally { conn.Close(); conn.Dispose(); } } </code></pre> <p>RequestAction model:</p> <pre><code>public class RequestAction { public string appId { get; set; } public string custId { get; set; } public string oprId { get; set; } public string businessProcess { get; set; } public string action { get; set; } public string[] actionKeys { get; set; } public string actionKey { get; set; } } </code></pre> <p>When I debug, I step through the method and when I get to the foreach loop, I get a null object reference. Looking in my locals section, all my properties for requestAction are null. I have tried prefixing the object with the [FromBody] tag to no avail after reading a few related articles. Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload