Data is coming in null to controller
Data is coming in null to controller
Matthew Czajka
Posts: 13Questions: 4Answers: 1
in Editor
I have a DataTable with and editor to make 3 different calls to the backend controller. When I look to see the data being passed, I notice it is null. I'm not sure how I should format or setup the controller method or the ajax requests so I can read the data for the create, edit and delete methods. My code is attached.
Answers
At what point? If you use the browser's network inspector tools, do you see the data being sent to the server? Or is it null at the server when trying to reference it?
Allan
It is null at the server when trying to reference it. In the browser's network tools I see the request url, but it's not being pulled into the Controller correctly. I believe either I am not sending it correctly through AJAX as I am expecting, or I am not pulling in the object correctly into the Controller. I'm not sure which one or what to do about it.
Your controller doesn't appear to be doing much at the moment, and isn't referencing the POSTed data. I would normally expect to see a reference to
Request.Form
or similar. See our .NET documentation here.Allan
I knew I was missing something, but I wasn't entirely sure. The .NET documentation didn't help me at all but your mention of Request.Form helped me look elsewhere on the internet. I was able to get a solution working where the Create and Edit methods use HttpContext.Request.Form
IFormCollection data = HttpContext.Request.Form;
And for the Delete method I am using HttpContext.Request.QueryIQueryCollection data = HttpContext.Request.Query;
where I am able to create a dictionary variable out of the keys in the data collections.var dict = new Dictionary<string, string>();
foreach (var key in data.Keys)
{
StringValues @value = new StringValues();
data.TryGetValue(key, out @value);
dict.Add(key, @value.ToString());
}
Good to hear that helped. I'm guessing you aren't planning on using our .NET libraries then?
Allan
I am not using the libraries at this time as I'm not sure how exactly to handle the Editor class and use it amongst multiple tables and multiple actions.
I see you're using Editor in your example, but our accounts aren't showing that you have a license - it just reports that your trial expired in 2015. Is the license registered to another email address? Please can let us know so we can update our records and provide support.
Thanks,
Colin
I am currently on the trial license right now and I registered this account on Sept. 10th this year. I am not sure what your reports are pulling unless it is pulling a different account that may have been registered to my old company's email. I am currently on matthew.czajka@iimak.com while I may have come onto this site in 2015 with the email matthew.czaja@gdit.com. That may be the confusion.
Thanks for letting us know.
Also thanks for the feedback on the libraries. Possibly the documentation here might help with the multiple tables if you did want to give it a go: https://editor.datatables.net/manual/net/joins .
Allan