Я делаю пост-запрос с api fetch, в тот момент, когда я достигаю точки останова, параметры приходят или сообщают мне, что они нулевые, поэтому эта часть генерирует ошибку, я уже проверил переменные, которым она назначает html объекты, переменные, которые вы отправили: идентификация пользователя, дата начала и дата окончания, эти данные были отправлены объекту, для которого требуется метод C #, поэтому он выполняет запрос с необходимой мне информацией, которую я хочу знать, почему при выполнении этого метода он возвращает нулевые данные в бэкэнд, код приложения и рабочий образ
Просмотр
@using System.Globalization
@using Microsoft.AspNetCore.Http.Features
@using Microsoft.AspNetCore.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@{
ViewData["Title"] = "Reporte Rh";
}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-header with-border">
<h3 class="box-title text-primary"><i class="fa fa-building-o"></i> @ViewData["Title"]</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
title="Collapse">
<i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
<i class="fa fa-times"></i>
</button>
</div>
</div>
<div class="box-body">
<div id="Grid">
<form role="form" method="post">
<div class="form-group has-success">
<label class="control-label" for="inputSuccess"><i class="fa fa-check"></i>@Localizer["Cedula"]</label>
<input type="text" class="form-control" id="cedula" placeholder="Enter ...">
</div>
<label for="start" class="control-label">Start date:</label>
<input type="date" class="form-control" id="start" name="trip-start"
value="2018-07-22"
min="2018-01-01" max="3000-12-31">
<label for="start" class="control-label">And date:</label>
<input type="date" class="form-control" id="end" name="trip-start"
value="2018-07-22"
min="2018-01-01" max="3000-12-31">
<!-- /.col Botom-->
<div class="col-xs-4">
<button type="button" class="btn btn-primary btn-sm" onclick="ValidarExisteContacto()">@Localizer["Reporte"]</button>
</div>
</form>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script src="~/Scripts/ReporteRh/ValidacionReporteReporteRh.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
function ValidarExisteContacto() {
var existeUsuario;
if ($("#cedula").val() !== null || $("#start").val() !== null || $("#end").val() !== null) {
//const url = '/ReporteRh/CreatePdfs';
var url = '/ReporteRh/CreatePdfs';
var cedula = $("#cedula").val();
var start = $("#start").val();
var end = $("#end").val();
const myPost = {
cedula: cedula,
start: start,
end: end
};
fetch(url, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(myPost)
}).then((res) => {
if (res.ok) {
existeUsuario = true;
console.log(res);
return res.json();
} else {
existeUsuario = false;
console.log(res);
return Promise.reject({ status: res.status, statusText: res.statusText });
}
})
.then((data) => console.log(data))
.catch(err => console.log('Error message:', err.statusText) );
}
return existeUsuario;
}
/// <summary>
/// Metodo para el reporte
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public FileResult CreatePdfs(ReporteLabViewModels model)
{
//ReporteLabViewModels model = new ReporteLabViewModels();
MemoryStream workStream = new MemoryStream();
StringBuilder status = new StringBuilder("");
DateTime dTime = DateTime.Now;
//Crea archivo con nombre
string strPDFFileName = string.Format("SamplePdf" + dTime.ToString("yyyyMMdd") + "-" + ".pdf");
if (model.cedula != null)
{
var sql = from d in demoDrHelpContext.DatosPacientes
join rh in demoDrHelpContext.Rh on d.Id equals rh.IdPaciente
join gr in demoDrHelpContext.GrupoSanguineo on rh.IdGrupoSanguineo equals gr.Id
join nt in demoDrHelpContext.NotificacionExamen on d.Id equals nt.IdPaciente
where nt.FechaRegistro >= model.start && nt.FechaRegistro <= model.end && d.Codigo == model.cedula
select new { d.Nombre, d.Codigo, d.Edad, gr.Sigla, nt.FechaRealizada };
if (sql == null)
{
foreach (var grouprh in sql)
{
#region Area del reporte pdf
iTextSharp.text.Document doc = new iTextSharp.text.Document();
doc.SetMargins(0f, 0f, 0f, 0f);
//Crea PDF Table con 5 columnas
PdfPTable tableLayout = new PdfPTable(5);
doc.SetMargins(0f, 0f, 0f, 0f);
//Create PDF Table
PdfWriter.GetInstance(doc, workStream).CloseStream = false;
doc.Open();
// Crear un ImageData object
//Agrega la tabla del pdf
string imageURL = "C:/Apoyo Mederic/archive/APOYO MEDERI-1.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
iTextSharp.text.Image jpgs = iTextSharp.text.Image.GetInstance(imageURL);
//Cambiar el tamaño de la imagen depende de su necesidad
jpg.ScaleToFit(120f, 100f);
//Dar espacio antes de la imagen
jpg.SpacingBefore = 10f;
//Dar algo de espacio después de la imagen.
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
// Escribimos el encabezamiento en el documento
Font fonts = new Font(FontFamily.HELVETICA, 8, Font.BOLD);
doc.Add(new Paragraph(dTime.ToString("dd/MM/yyyy"), fonts));
doc.Add(Chunk.NEWLINE);
// Este codigo genera una tabla de 3 columnas
PdfPTable tablets = new PdfPTable(2);
tablets.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Font font = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
Paragraph pLong = new Paragraph("LABORATORIO CLINICO", font);
pLong.Alignment = Element.ALIGN_CENTER;
doc.Add(pLong);
// Creando una tabla
float[] pointColumnWidths = { 150F, 150F };
PdfPTable tablew = new PdfPTable(pointColumnWidths);
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(jpg);
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase("Numero Documeno ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase("Nombre ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase("Fecha ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(grouprh.FechaRealizada.ToString(), new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
//tablew.AddCell(new PdfPCell(new Phrase("Activo ", new Font(Font.FontFamily.HELVETICA, 14, 1,
// new iTextSharp.text.BaseColor(0, 0, 0))))
//{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
//tablew.AddCell(new PdfPCell(new Phrase(genero.Activo.ToString(), new Font(Font.FontFamily.HELVETICA, 14, 1,
// new iTextSharp.text.BaseColor(0, 0, 0))))
//{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar tabla al documento
doc.Add(tablew);
doc.Add(tablets);
doc.Add(Add_Content_To_PDFS(tableLayout, model));
// Cierra el documento
doc.Close();
#endregion
}
}
else
{
foreach (var grouprh in sql)
{
#region Area del reporte pdf
iTextSharp.text.Document doc = new iTextSharp.text.Document();
doc.SetMargins(0f, 0f, 0f, 0f);
//Crea PDF Table con 5 columnas
PdfPTable tableLayout = new PdfPTable(5);
doc.SetMargins(0f, 0f, 0f, 0f);
//Create PDF Table
PdfWriter.GetInstance(doc, workStream).CloseStream = false;
doc.Open();
// Crear un ImageData object
//Agrega la tabla del pdf
string imageURL = "C:/Apoyo Mederic/archive/APOYO MEDERI-1.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
iTextSharp.text.Image jpgs = iTextSharp.text.Image.GetInstance(imageURL);
//Cambiar el tamaño de la imagen depende de su necesidad
jpg.ScaleToFit(120f, 100f);
//Dar espacio antes de la imagen
jpg.SpacingBefore = 10f;
//Dar algo de espacio después de la imagen.
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
// Escribimos el encabezamiento en el documento
Font fonts = new Font(FontFamily.HELVETICA, 8, Font.BOLD);
doc.Add(new Paragraph(dTime.ToString("dd/MM/yyyy"), fonts));
doc.Add(Chunk.NEWLINE);
// Este codigo genera una tabla de 3 columnas
PdfPTable tablets = new PdfPTable(2);
tablets.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Font font = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
Paragraph pLong = new Paragraph("LABORATORIO CLINICO", font);
pLong.Alignment = Element.ALIGN_CENTER;
doc.Add(pLong);
// Creando una tabla
float[] pointColumnWidths = { 150F, 150F };
PdfPTable tablew = new PdfPTable(pointColumnWidths);
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(jpg);
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Adding cells to the table
tablew.AddCell(new PdfPCell(new Phrase("Codigo ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(grouprh.Codigo.ToString(), new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase("Nombre ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(grouprh.Nombre.ToString(), new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase("Activo ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
tablew.AddCell(new PdfPCell(new Phrase(grouprh.FechaRealizada.ToString(), new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar celdas a la tabla
tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT }); tablew.AddCell(new PdfPCell(new Phrase(" ", new Font(Font.FontFamily.HELVETICA, 14, 1,
new iTextSharp.text.BaseColor(0, 0, 0))))
{ Border = 0, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_RIGHT });
// Agregar tabla al documento
doc.Add(tablew);
doc.Add(tablets);
GrupoSanguineoViewModels rhViewmModels = new GrupoSanguineoViewModels
{
Sigla = grouprh.Sigla
};
doc.Add(Add_Content_To_PDF(tableLayout, rhViewmModels));
// Cierra el documento
doc.Close();
#endregion
}
}
}
byte[] byteInfo = workStream.ToArray();
workStream.Write(byteInfo, 0, byteInfo.Length);
workStream.Position = 0;
return File(workStream, "application/pdf", strPDFFileName);
}
Демонстрация со стороны браузера