Home > front end >  How to submit related entities in asp.net core razor page form?
How to submit related entities in asp.net core razor page form?

Time:11-20

I have two models Invoice and Product, one invoice can have many products as usual.

public class InvoiceModel
{
    public string Name { get; set; }
    public string Description { get; set; }

    [Required(ErrorMessage = "Products are required!")]
    public List<ProductModel> Products { get; set; }

}

public class ProductModel
    {
        public string Name { get; set; }
        public string Model { get; set; }
        public string Brand { get; set; }
    }

and i want to create a new invoice with products.

so when i generate razor page for invoice create, it only generate input fields for Name and Description,

enter image description here

then i added product table, and button to the form, when the user clicks on add product button, a new row is added to the table using jsscript.

enter image description here

I have referred to this enter image description here

  • Related