We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Master Detail Form with ASP.NET CORE

Hi,

I am carrying out a project where I need to consume the data of the header in a form and the detail, to obtain the 2 through a button and save the information in the database.
Try using an example from here:


https://www.syncfusion.com/forums/153054/master-detail-form


But it is for .net MVC and I need it for .net core. Your help please!

3 Replies 1 reply marked as answer

PG Praveenkumar Gajendiran Syncfusion Team April 14, 2021 01:27 PM UTC

Hi Luis,

Thanks for contacting Syncfusion support. 
Based on your request, we have prepared a same sample in .net core, please check the below for your reference,

Sample: https://www.syncfusion.com/downloads/support/forum/164511/ze/UrlAdaptor-CRUD-BatchMode-1491190615.zip 
Note: We would like to inform you that in the above sample since Grid is rendered inside the form element it will automatically be submitted when clicking any submit button inside the form.


Regards,
Praveenkumar G
 


Marked as answer

LU Luis April 14, 2021 05:40 PM UTC

Hi,

I have a problem. 
I just need to add records to the grid and then save them to the database. For this, I use part of the code sent, but it does not recognize the type of object that I have.



In addition to this, I would like to know the way in which the header data (ejs-maskedtextbox) is sent to save it in the database. I don't really understand how it works.

Hope I don't bother you with so many queries, I am new to using syncfusion.

I attach my work:

I think the problem is because I am using the urldatasource wrong

CONTROLLER:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Facturacion.Models;
using Syncfusion.EJ2.Base;
using Microsoft.EntityFrameworkCore;
using System.Collections;
using Newtonsoft.Json;

namespace Facturacion.Controllers
{
    public class Factura : Controller
    {
        FacturacionContext ctx;

        public static List order = new List();

        public Factura(FacturacionContext _ctx)
        {
            ctx = _ctx;
        }

        public ActionResult Index()
        {
            //usando linq
            //ViewBag.cabecera = ctx.VenTransaccioncabeceras.ToArray();
            //ViewBag.detalle = ctx.VenTransacciondetalles.ToArray();
            //ViewBag.Items = ctx.Items.ToArray();
            if (order.Count == 0)
            ViewBag.data = order;
            var childData = ctx.VenTransacciondetalles.ToArray();
            var emp = ctx.VenTransacciondetalles.ToArray();
            ViewBag.foreign = emp;
            return View();
        }

        public ActionResult Listado(){

            ViewBag.listado = ctx.Listados.FromSqlRaw("select * from fn_listar_facturas(1);").ToList().ToArray();
            return View();
        }

        public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
        {
            var formData = Json(new
            {
                Data = JsonConvert.DeserializeObject(batchmodel.formData)
                
            });

            if (batchmodel.Added != null)
            {
                for (var i = 0; i < batchmodel.Added.Count(); i++)
                {
                    order.Insert(0, batchmodel.Added[i]);
                }
            }
            var data = order.ToList();
            return Json(data);

        }


        public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
        {
            IEnumerable DataSource = order;
            DataOperations operation = new DataOperations();
            if (dm.Search != null && dm.Search.Count > 0)
            {
                DataSource = operation.PerformSearching(DataSource, dm.Search);  //Search
            }
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
            {
                DataSource = operation.PerformSorting(DataSource, dm.Sorted);
            }
            if (dm.Where != null && dm.Where.Count > 0) //Filtering
            {
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
            }
            int count = DataSource.Cast().Count();
            if (dm.Skip != 0)
            {
                DataSource = operation.PerformSkip(DataSource, dm.Skip);         //Paging
            }
            if (dm.Take != 0)
            {
                DataSource = operation.PerformTake(DataSource, dm.Take);
            }
            Console.Write(DataSource);
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
        }



        public class CRUDModel
        {
            public List Added { get; set; }
            public List Changed { get; set; }
            public List Deleted { get; set; }
            public VenTransacciondetalle Value { get; set; }
            public string formData { get; set; }
            public int key { get; set; }
            public string action { get; set; }
        }


    }
}

MODEL:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

#nullable disable

namespace Facturacion.Models
{
    [Table("ven_transacciondetalle")]
    public partial class VenTransacciondetalle
    {
        [Key]
        [Column("det_id")]
        public int DetId { get; set; }
        [Column("cab_id")]
        public int CabId { get; set; }
        [Column("ite_id")]
        public int IteId { get; set; }
        [Column("det_cantidad")]
        public decimal? DetCantidad { get; set; }
        [Column("det_precio")]
        public decimal? DetPrecio { get; set; }
        [Column("det_total")]
        public decimal? DetTotal { get; set; }
        [Column("det_estado")]
        [StringLength(1)]
        public string DetEstado { get; set; }

        [ForeignKey(nameof(CabId))]
        [InverseProperty(nameof(VenTransaccioncabecera.VenTransacciondetalles))]
        public virtual VenTransaccioncabecera Cab { get; set; }
        [ForeignKey(nameof(IteId))]
        [InverseProperty(nameof(Item.VenTransacciondetalles))]
        public virtual Item Ite { get; set; }
    }
}






PG Praveenkumar Gajendiran Syncfusion Team April 15, 2021 05:50 PM UTC

Hi Luis, 

Thanks for your update.  

We checked your query and provided information and in that we could see that the Grid has null data source at initial rendering. We would like to inform you that by default the Grid column type will be set based on that column data source’s first value. And if the first row of a column contains undefined or null then the column type needs to be defined for that as with this initial row data value, then only the column type will be set and based on the column type the filtering and other Grid actions will be performed. 

So if null or undefined value is present for a column in the initial row data and column type is not set for that, then the type will be set as ‘null’ which causes problems as you reported. This is the Grid’s default behavior. So we suggest you to resolve this by setting the column type in-case the Grid row data has null or undefined value. 

More details on this can be checked in the below documentation link, 

Regards,
Praveenkumar G 


Loader.
Up arrow icon