.NET equivalent to .php " ->where( 'site', $_POST['site'] )"

.NET equivalent to .php " ->where( 'site', $_POST['site'] )"

JormJorm Posts: 16Questions: 4Answers: 0

I'm implementing a parent-child relationship as described here: https://datatables.net/blog/2016-03-25

I've got parent data coming through, and when I hard code a value into the .Where clause of the related ApiController, the 'child' table returns data. Of course what I really want is for the child tables data to be dictated by the parent selection....

I've scoured through the Editor for .NET examples, but can't find one where a parameter is being passed to the controller and eventually seeds the 'where' clause that lives there.

The example at the link given above shows server-side .php notation to get the parameter from the selection made on the parent table: " ->where( 'site', $_POST['site'] )"

Much obliged if someone can point me to a source, or knows, the .NET equivalent to this line of code?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    request.Form["propertyName"] should do it - for example:

    public class StaffController : ApiController
    {
        [Route("api/staff")]
        [HttpGet]
        [HttpPost]
        public IHttpActionResult Staff()
        {
            var request = HttpContext.Current.Request;
            var settings = Properties.Settings.Default;
    
            if (!string.IsNullOrEmpty(request.Form["site"])) {
                return;
            }
     
            using (var db = new Database(settings.DbType, settings.DbConnection))
            {
                var response = new Editor(db, "users")
                    .Model<UserModel>()
                    ...
                    .Where("site", request.Form["site"])
                    .Process(request)
                    .Data();
     
                return Json(response);
            }
        }
    }
    

    I don't actually have VS on this machine so its possible I've done something daft there, and I can't for the life of me remember the syntax for returning an empty JSON object on error, but that should do the job.

    Allan

  • JormJorm Posts: 16Questions: 4Answers: 0

    Thank you thank you! I had found reference to 'request.Form', but I was typing 'Request' capital 'R'.... Gargh, I've got some learning to do.

    Best,
    -jorm

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Funnily enough Request I think would work on an MVC page (can't remember for certain, but I've used it a few times myself somewhere and think it was there...).

    The number of "globals" has been much cause of grief for me too - you aren't alone :).

    Allan

This discussion has been closed.