Hi, Good morning all, I am new to asp.net core 6.0 and i have this issues...
I have this model Called OrderModel, inside it I have order class and orderDetails Class
C#
public class Order
{
[Key]
public int OrderId { get; set; }
[Display(Name = "Customer Name")]
[Required(ErrorMessage = "Please Select Customer Name")]
public String CustomerName { get; set; }
public ICollection? OrderDetails { get; set; }
}
public class OrderDetail
{
[Key]
public int DetailId { get; set; }
public int OrderId { get; set; }
[Display(Name = "Service")]
public string ServiceName { get; set; }
[Display(Name = "Quantity")]
public int Quantity { get; set; }
[Display(Name ="Unit Price")]
public float UnitPrice { get; set; }
[ForeignKey("OrderId")]
public Order? Order { get; set; }
}//On my view, I want to be able to display the Order Class as a form and the OrderDetails as an editable table with 10 rows ..
C#
public IActionResult Customer_Order()
{
// I want to be able to display upto 10 rows..
List od = new List();
od.Add(new OrderDetail { DetailId = 0, Discount = 0, Quantity = 0, ServiceName = "Select Service", UnitPrice = 0, TotalAmount = 0 });
od.Add(new OrderDetail { DetailId = 0, Discount = 0, Quantity = 0, ServiceName = "Select Service", UnitPrice = 0, TotalAmount = 0 });
return View(od);
}On Post, I want to be able to save the data to both order table and orderdetails table
TypeScript
@model Customer.Models.Order
---Customer---
SN
Services
Qty/Hrs
Unit Price
Total
int j = 0;
@foreach (var item in Model.OrderDetails)
{
@Html.DropDownListFor(model=>item.ServiceName, ViewBag.ServiceID as List, "Please Select", new{@class ="form-control dropdownlist select2"})
@Html.EditorFor(model=>item.Quantity)
@Html.EditorFor(model=>item.UnitPrice)
@Html.EditorFor(model=>item.TotalAmount)
}How do i display data into
Thank you very much for your lovely time..

Jay Krishna ReddyRank #152 · 15.2K reputationPosted May 30, 2022, 6:05 AM EDT
, List>(GetTeachers(), GetStudents());
, List>
@ViewBag.Message
Teacher List
Student List
pius joshua31 reputationPosted May 30, 2022, 7:27 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 30, 2022, 12:33 PM EDT