Editor .Net Core: System.ArgumentNullException: 'Value cannot be null. '
Editor .Net Core: System.ArgumentNullException: 'Value cannot be null. '
equezadajej
Posts: 8Questions: 2Answers: 0
I'm using Editor 2.0.8 for .Net Core and I got into the following issue and the exception doesn't have enough details to know why it's happening:
It's able to correctly upload the file, but it fails when I try adding to the table TBOrdenCompra
.
Stacktrace:
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at DataTables.Editor._InsertOrUpdate(Object id, Dictionary`2 values)
at DataTables.Editor._Insert(Dictionary`2 values)
at DataTables.Editor._Process(DtRequest data)
at DataTables.Editor.Process(DtRequest data)
at DataTables.Editor.Process(IEnumerable`1 data, String culture)
at DataTables.Editor.Process(HttpRequest request, String culture)
at SistemaInventario.Controllers.MantenedoresController.OrdenDeCompra() in C:\Repositorios\Web\HH2.2\SistemaInventario\Controllers\MantenedoresController.cs:line 189
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Controller code:
[Route("api/OrdenDeCompra")]
[HttpGet]
[HttpPost]
public ActionResult OrdenDeCompra()
{
var dbType = Environment.GetEnvironmentVariable("DBTYPE");
var dbConnection = Environment.GetEnvironmentVariable("DBCONNECTION");
using (var db = new Database(dbType, dbConnection))
{
var update = Format.DATE_ISO_8601;
var response = new Editor(db, "DBInventario.dbo.TBOrdenCompra", "idOrdenCompra")
//.Model<TipoActivoModel>()
.Field(new Field("DBInventario.dbo.TBOrdenCompra.idOrdenCompra"))
.Field(new Field("DBInventario.dbo.TBOrdenCompra.folioOrdenCompra")
.Validator(Validation.NotEmpty(new ValidationOpts { Message = "Campo requerido." }))
.Xss(false) //Permitir Acentos (á)
)
.Field(new Field("DBInventario.dbo.TBOrdenCompra.fechaOrdenCompra")
.Validator(Validation.DateFormat(
update,
new ValidationOpts { Message = "Ingrese fecha en formato aaaa-mm-dd." }
))
.GetFormatter(Format.DateSqlToFormat(update))
.SetFormatter(Format.DateFormatToSql(update))
)
.Field(new Field("DBInventario.dbo.TBOrdenCompra.idCliente")
.Options(new DataTables.Options()
.Table("DBCentral.dbo.TB11Clientes")
.Value("DBCentral.dbo.TB11Clientes.idCliente")
.Label(new List<string> { "IDCliente", "Descripcion"})
//.Label("Descripcion")
)
)
.Field(new Field("DBInventario.dbo.TBOrdenCompra.idArchivo")
.Validator(Validation.NotEmpty(new ValidationOpts { Message = "Documento requerido." }))
.Upload(new Upload(Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot", "uploads/ordenesDeCompra", "__ID____EXTN__"))
.Db("TBArchivos", "idArchivo", new Dictionary<string, object>
{
{"rutaWeb", Path.DirectorySeparatorChar+Path.Combine("uploads/ordenesDeCompra", "__ID____EXTN__")},
{"rutaSistema", Upload.DbType.SystemPath},
{"nombreArchivo", Upload.DbType.FileName},
{"tamanoArchivo", Upload.DbType.FileSize}
})
.DbClean(data =>
{
foreach (var row in data)
{
// Do something;
}
return true;
})
.Validator(Validation.FileSize(5000000, "Excede tamaño máximo 5MB."))
.Validator(Validation.FileExtensions(new[] { "pdf" }, "Sólo se admite extensión PDF."))
)
)
.LeftJoin("DBCentral.dbo.TB11Clientes", "DBInventario.dbo.TBOrdenCompra.idCliente", "=", "DBCentral.dbo.TB11Clientes.idCliente")
.TryCatch(false)
.Debug(true)
;
/*
response.PostCreate += (sender, e) => _LogChange(db, 1, e.Id, e.Values);
response.PostEdit += (sender, e) => _LogChange(db, 2, e.Id, e.Values);
response.PostRemove += (sender, e) => _LogChange(db, 3, e.Id, e.Values);
*/
var aaaa = response.Process(Request);
var bbbb = aaaa.Data();
return Json(bbbb);
}
Client initialization:
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: "/api/OrdenDeCompra",
table: "#example",
fields: [
{
label: "Folio OC",
name: "DBInventario.dbo.TBOrdenCompra.folioOrdenCompra"
},
{
label: 'Fecha OC',
name: 'DBInventario.dbo.TBOrdenCompra.fechaOrdenCompra',
type: 'datetime',
def: function () { return new Date(); }
}, {
label: "N° Centro Costo",
name: "DBInventario.dbo.TBOrdenCompra.idCliente",
type: "select2",
}, {
label: "Archivo",
name: "DBInventario.dbo.TBOrdenCompra.idArchivo",
type: "upload",
display: function (file_id) {
return '<a href="' + editor.file('TBArchivos', file_id).rutaWeb + '" target="_blank">Descargar</a>';
},
clearText: "Eliminar",
noImageText: 'Sin Archivo',
noFileText: 'Sin archivo elegido',
uploadText: 'Elegir archivo...',
dragDropText: 'Arrastra y suelta el archivo aquí para subir'
}
]
});
$('#example').DataTable({
dom: "Bfrtip",
ajax: "/api/OrdenDeCompra",
columns: [
{ data: "idOrdenCompra" },
{ data: "folioOrdenCompra" },
{ data: 'fechaOrdenCompra' },
{
data: "idArchivo",
render: function (file_id) {
return file_id ?
'Archivo cargado' :
null;
},
defaultContent: "Sin archivo",
title: "Archivo"
}
],
order: [
//[3, 'asc'], [0, 'asc']
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
});
});
SQL Server Tables:
CREATE TABLE [dbo].[TBOrdenCompra](
[idOrdenCompra] [int] IDENTITY(1,1) NOT NULL,
[folioOrdenCompra] [varchar](30) NOT NULL,
[fechaOrdenCompra] [date] NOT NULL,
[idCliente] [int] NOT NULL,
[idArchivo] [int] NULL,
CONSTRAINT [PK_TBOrdenCompra] PRIMARY KEY (idOrdenCompra),
CONSTRAINT [FK_TBOrdenCompra_1] FOREIGN KEY ([idArchivo]) REFERENCES [dbo].[TBArchivos] ([idArchivo])
);
CREATE TABLE [dbo].[TBArchivos](
[idArchivo] [int] IDENTITY(1,1) NOT NULL,
[nombreArchivo] [nvarchar](250) NULL,
[tamanoArchivo] [int] NULL,
[rutaWeb] [nvarchar](250) NULL,
[rutaSistema] [nvarchar](250) NULL,
CONSTRAINT [PK_TBArchivos] PRIMARY KEY ([idArchivo])
);
Answers
Hi,
I suspect it is something to do with the use of the schema name. Is this error happening after the upload has completed and you then submit the form, or while you are uploading the file? From the error message and backtrace, I suspect the former. If that is the case, can you show me the response from the server for the upload action please?
Many thanks,
Allan
Hi Allan,
It is happening after the upload, when submitting the form.
I can confirm that it at least uploads the file and inserts the data to the
TBArchivos
SQL table.Server's response of the upload action:
Super - thanks for that. I will try to reproduce the issue here with that information and get back to you. The upload response looks good - so I suspect it is how the field name is handled with the multi-levels of nesting.
Allan
Any news about this?
Apologies, not yet. I've not yet had a chance to build up an example. Hoping to do so soon.
Allan