asp.net-mvcasp.net-dynamic-data

.Net RunTimeBinderException


I have a data content witch contains complex data I just need index names which seem in Dynamic View in data. In debug mode I can see the datas but cant get them..

You can see the contents of data in image below)enter image description here:

 if(hits.Count() > 0)
            {
                var data = hits.FirstOrDefault().Source;
                var dataaa = JsonConvert.DeserializeObject(hits.FirstOrDefault().Source);
            }

Solution

  • I found a solution with checking if selected index has documents; if yes, I take the first document in index, and parse it to keys(field names) in client. here is my func:

    [HttpPost]
            public ActionResult getIndexFields(string index_name)
            {
                var node = new Uri("http://localhost:9200");
                var settings = new ConnectionSettings(
                    node,
                    defaultIndex: index_name
                );
                var esclient = new ElasticClient(settings);
                var Documents = esclient.Search<dynamic>(s => s.Index(index_name).AllTypes().Source());
                string fields = "";
                if (Documents.Documents.Count() > 0)
                {
                    fields = JsonConvert.SerializeObject(Documents.Documents.FirstOrDefault());
                    var data = Documents.Documents.FirstOrDefault().Source;
                    return Json(new
                    {
                        result = fields,
                        Success = true
                    });
                }
    
                return Json(new
                {
                    result = "",
                    Success = false
                });
    
            }
    

    and my js:

    $.ajax({
                url: "getIndexFields?index_name=" + $(this).val(),
                type: "POST",
                success: function (data) {
                    if (data.Success) {
                        var fields = JSON.parse(data.result);
                        var fields_arr = [];
                        $.each(fields, function (value, index) {
                            fields_arr.push(
                                {
                                    id: value,
                                    label: value
                                })
                        });
                        options.filters = fields_arr;
                        var lang = "en";//$(this).val();
    
                        var done = function () {
                            var rules = $b.queryBuilder('getRules');
                            if (!$.isEmptyObject(rules)) {
                                options.rules = rules;
                            }
                            options.lang_code = lang;
                            $b.queryBuilder('destroy');
                            $('#builder').queryBuilder(options);
                        };
                        debugger
                        if ($.fn.queryBuilder.regional[lang] === undefined) {
                            $.getScript('../dist/i18n/query-builder.' + lang + '.js', done);
                        }
                        else {
                            done();
                        }
                    }
                    else {
                        event.theme = 'ruby';
                        event.heading = '<i class=\'fa fa-warning\'></i> Process Failure';
                        event.message = 'User could not create.';
                        event.sticky = true;
                        $("#divfailed").empty();
                        $("#divfailed").hide();
                        $("#divfailed").append("<i class='fa fa-warning'></i> " + data.ErrorMessage);
                        $("#divfailed").show(500);
                        setTimeout(function () {
                            $("#divfailed").hide(500);
                        }, 3000);
                    }
                },
                error: function (a, b, c) {
                    debugger
                    event.theme = 'ruby';
                    event.heading = '<i class=\'fa fa-warning\'></i> Process Failure';
                    event.message = 'Object could not create.';
                    $("#divfailed").empty();
                    $("#divfailed").hide();
                    msg = c !== "" ? c : a.responseText;
                    $("#divfailed").append("<i class='fa fa-warning'></i> " + msg);
                    $("#divfailed").show(500);
                    setTimeout(function () {
                        $("#divfailed").hide(500);
                    }, 3000);
                }
            });