controller Where statement not getting data
controller Where statement not getting data
I must be missing something but I am not seeing it.
I have the following in the controller:
public class SystemUsersLineItemsController : ApiController
{
[Route("api/SystemUsersLineItems")]
[HttpGet]
[HttpPost]
public IHttpActionResult SystemUsersLineItems()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "SystemUsers_LineItems", "UserLineItemID")
.Model<SystemUsersLineItemsModel>("SystemUsers_LineItems")
.Field(new Field("SystemUsers_LineItems.SystemUserID")
.Options(new Options()
.Table("SystemUsers")
.Value("SystemUserID")
.Label(new[] { "FirstName", "LastName" })
.Render(row => row["LastName"] + ", " + row["FirstName"])
)
)
.LeftJoin("SystemUsers", "SystemUsers.SystemUserID", "=", "SystemUsers_LineItems.SystemUserID")
.Field(new Field("SystemUsers.FirstName"))
.Field(new Field("SystemUsers.LastName"))
.Where("SystemUsers_LineItems.SystemUserID", request.Form["userIDFilter"])
.Debug(true)
.Process(request)
.Data();
return Json(response);
}
}
}
and the following in the dataTable:
ajax: {
url: 'api/SystemUsersLineItems',
data: function (d) {
var selected = SystemUsersTable.row({ selected: true });
if (selected.any()) {
d['userIDFilter'] = selected.data().SystemUsers.SystemUserID;
console.log("idFilter",selected.data().SystemUsers.SystemUserID);
}
}
},
now, in the console.log I see:
idFilter 64027
so I know 'userIDFilter' is populated
however, I don't get the correct data and looking at the debug from the controller I see:
WHERE [SystemUsers_LineItems].[SystemUserID] IS NULL
Also, in the the browser developer tools --> network --> header --> Query String parameters I see:
userIDFilter: 64027
So why is request.Form["userIDFilter"] returning NULL
This question has an accepted answers - jump to answer
Answers
Guessing you are using ASP.Net. I don't myself so this is a guess but it looks like you need
Request.Form["userIDFilter"]
instead ofrequest.Form["userIDFilter"]
. Notice the capitalR
. See this SO thread.Kevin
no, here request (with lower case r) is from line 8 in the controller posted above.
I went ahead and changed it so I am passing the ID number as a parameter, but I don't understand why it isn't working as posted above because I have done this many times before.
here is what i ended up doing this time:
and called it like this:
request.Form["userIDFilter"]
is populated when your POST the data to the server. So you need to addtype: 'POST'
to yourajax
object.Edit By default DataTables sends a GET request.
Allan
aaah, yes. thank you.