Trying to get value of a field for additional server-side processing

Trying to get value of a field for additional server-side processing

mike92117mike92117 Posts: 38Questions: 11Answers: 1

I have using .net libraries and in my controller action that is creating or updating a record (POST, not a GET), I need to get the values of the record being edited for additional server-side processing. I thought I could use the Field("field_name") api on the server side but that doesn't seem to work even though these values are seemingly passed in (see snippet). I want to get the values of Rsm and Rlg, which are floating point values. Do I need to just dig into the Request object to get these? Is that what the Editor class does internally?

                    var response = new Editor(db, "XProfile", "ID")
                                        .Model<XProfile>()
                                        .Field(new Field("ID"))
                                        .Field(new Field("Name"))
                                        .Field(new Field("Description"))
                                        .Field(new Field("Rsm").Validator(Validation.Numeric()))
                                        .Field(new Field("Rlg").Validator(Validation.Numeric()))
                                        .TryCatch(false)
                                        .Process(Request)
                                        .Data();

This question has an accepted answers - jump to answer

Answers

  • mike92117mike92117 Posts: 38Questions: 11Answers: 1

    Actually, straightforward to get the values from the Request object. You need the correct keys, which are in a collection in Request.Form.Keys. The keys are in the form of data[row_3][Rsm].

                if (request.Method == "POST")
                {
                    ICollection<String> keys = Request.Form.Keys;
                    
                    foreach(var k in keys)
                    {
                        int leftBracket = k.LastIndexOf('[');
                        int rightBracket = k.LastIndexOf(']');
                        if (leftBracket == -1 || rightBracket == -1)
                            continue;
                        string keyVal = k.Substring(leftBracket+1, rightBracket-leftBracket - 1);
                        var s = Request.Form[k];
                        if (Double.TryParse(s, out x))
                            dict.Add(keyVal, x);
                    }
                    if(dict.ContainsKey("Rlg"))
                    {
                        double rlg = dict["Rlg"];
                        OtherServerSideProcessing(rlg);
                    }
                }
    
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Hi,

    You might also want to take a look at the events such as PreEdit and PreCreate that the .NET libraries can fire. Docs on them here. They can be really useful for performing extra operations per row.

    Allan

  • mike92117mike92117 Posts: 38Questions: 11Answers: 1

    Thanks Allan - I'll take a look!

Sign In or Register to comment.