Click here to Skip to main content
15,887,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Problem

How to bind sales header Model to collection of sales Line using asp.net core 2.1 ?
I work on project have Sales Order form this form contain to
salesHeader
salesFooter
so that i already have model Sales Header have navigation property to Sales Footer
as following
SalesHeader Model

C#
public int SalesOrderNo { get; set; }
  public int SalesYear { get; set; }
  public ICollection<SalesFooter> SalesFooters { get; set; }


C#
SalesFooter Model
public int SalesOrderNo { get; set; }
public int Quantity { get; set; }
public int UnitPrice { get; set; }


How to get collection of sales footer on Edit Action of Sales Header controller And Edit View Of Sales Header controller please ?
1- on Edit action of sales header controller how to get collection of sales footer ?
2- on Edit view(get) sales header controller how to get collection of sales footer ?


What I have tried:

public class SalesOrderController : Controller
    {
        private readonly IrepositoryTab<SalesHeader> _repositoryHeader;
        public  SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter)
        {
            this._repositoryHeader = SalesHeader;
            this._repositoryFooter = SalesFooter;
         
        }

//get
public IActionResult Edit(int? id)
       {

           var SalesHeader = _repositoryHeader.GetById(id);
          //How to bind with sales footer
           return View();

       }

on Edit view
 <div class="form-group">
                <label asp-for="SalesOrderNo" class="control-label"></label>
                <input asp-for="SalesOrderNo" class="form-control" />
                <span asp-validation-for="SalesOrderNo" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="SalesYear" class="control-label"></label>
                <input asp-for="SalesYear" class="form-control" />
                <span asp-validation-for="SalesYear" class="text-danger"></span>
            </div>
//How to bind Sales Header with Sales Footer

on view of sales Header
Posted
Updated 3-Apr-19 2:52am

1 solution

Since the code, you've provided seems valid and you've not provided any error message and something stopped you from calling SalesHeader.SalesFooters my guess is that in your case SalesHeader.SalesFooters is null.
The probable reason for that is that your _repositoryHeader.GetById(id) implementation is missing Include calls which would fill your navigation property.
You can read more on this here
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900