Cannot read propert 'options' of null
Cannot read propert 'options' of null
.net 4.5 MVC
reference to Datatables 1.4.2.0
I am getting an error in dataTables.editor.js:
Javascript runtime error: Unable to get property 'options' of undefined or null reference
The block of code throwing the error is:
if ( json.options ) {
$.each( this.s.fields, function (name, field) {
if ( json.options[ name ] !== undefined ) {
that.field( name ).update( json.options[ name ] );
}
} );
}
For some reason the json object above is null. Am I missing an option for my datatable or editor? I can't link the page to you because it is domain authenticated ...
Here is my javascript:
var editor; $(document).ready(function () { var db = $("#selectDatabase").val(); var sdg = $("#textSDG").val(); $('#tableSamples').DataTable({ ajax: "/Validation/EditorData/?db=" + db + "&sdg=" + sdg, columns: [ { data: "dt_sample.sys_loc_code" }, { data: "dt_result.cas_rn" }, { data: "rt_analyte.chemical_name" }, { data: "dt_result.result_numeric" }, { data: "dt_result.detect_flag" }, { data: "dt_result.lab_qualifiers" }, { data: "dt_result.validator_qualifiers" }, { data: "dt_result.result_type_code" }, { data: "dt_result.validated_yn" }, { data: "dt_result.approval_a" }, { data: "dt_result.approval_b" }, { data: "dt_result.approval_c" }, { data: "dt_result.approval_d" }, ], tableTools: { sRowSelect: "os", aButtons: [ { sExtends: "editor_create", editor: editor }, { sExtends: "editor_edit", editor: editor }, { sExtends: "editor_remove", editor: editor } ] } }); editor = new $.fn.dataTable.Editor({ ajax: "/Validation/EditorData/?db=" + $("#selectDatabase").val() + "&sdg=" + $("#textSDG").val(), table: "#tableSamples", fields: [{ label: "Sample No.", name: "dt_sample.sys_loc_code" }, { label: "CAS No.", name: "dt_result.cas_rn" }, { label: "Parameter", name: "rt_analyte.chemical_name" }, { label: "Result", name: "dt_result.result_numeric" }, { label: "Det?", name: "dt_result.detect_flag" }, { label: "Lab Qual", name: "dt_result.lab_qualifiers" }, { label: "Val Qual", name: "dt_result.validator_qualifiers" }, { label: "Val Code", name: "dt_result.result_type_code" }, { label: "Validated", name: "dt_result.validated_yn" }, { label: "1", name: "dt_result.approval_a" }, { label: "2", name: "dt_result.approval_b" }, { label: "3", name: "dt_result.approval_c" }, { label: "4", name: "dt_result.approval_d" } ] }); });Here is my controller:
public ActionResult EditorData(string db, string sdg)
{
var request = System.Web.HttpContext.Current.Request;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = ConfigurationManager.AppSettings["DBServer"].ToString();
builder.InitialCatalog = db;
builder.UserID = ConfigurationManager.AppSettings["User ID"].ToString();
builder.Password = ConfigurationManager.AppSettings["Password"].ToString();
var settings = builder.ConnectionString;
using (var dbase = new DataTables.Database("sqlserver", settings))
{
var response = new Editor(dbase, db)
.Model<EditorTableModel>()
.Field(new Field("dt_result.cas_rn")
.Options("rt_analyte", "cas_rn", "cas_rn")
)
.LeftJoin("rt_analyte", "rt_analyte.cas_rn", "=", "dt_result.cas_rn")
.Field(new Field("dt_result.test_id")
.Options("dt_test", "test_id", "test_id")
)
.LeftJoin("dt_test", "dt_test.test_id", "=", "dt_result.test_id")
.Field(new Field("dt_test.test_id")
.Options("dt_sample", "sample_id", "sample_id")
)
.LeftJoin("dt_sample", "dt_sample.sample_id", "=", "dt_test.sample_id")
.Where("dt_sample.sample_source", "Lab", "<>")
.Where("dt_test.lab_sdg", sdg)
.Process(request)
.Data();
return Json(response);
}
Answers
Well - I believe that json is null because my ajax url is not being found.
I'm getting a 404 error and I'm not sure why.
Console shows this as the path not found:
http://localhost:54485/Validation/EditorData/?db=EQ_TEST&sdg=L14071728&_=1435583221241
Failed to load resource: the server responded with a status of 404 (Not Found)
I'm not sure why the '&_ 1435583221241' is at the end - maybe that is causing the problem?
The controller is called ValidationController and the Method definition is:
public ActionResult EditorData(string db, string sdg)
I've tried it as a Json result as well ... Why can't my ajax call find my controller here?
AH - got it ... I had used the example from the WebAPI portion of the manual that had a get and post attribute. Taking those off and now it found the actionresult ....