I am getting error .
Model.
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using Used_Clothing_Managment.Models.ListView;
namespace Used_Clothing_Managment.Models;
public class ItemMasterFile
{
public int CodeItem { get; set; }
public string? Descriptionitem { get; set; }
public string? BaleSize { get; set; }
public int? Weight { get; set; }
public int? SecId { get; set; }
public string? Packsize { get; set; }
public string? Alid { get; set; }
public int? Iduom { get; set; }
public DateTime? EntryDate { get; set; }
public int? Cid { get; set; }
public string? Icn { get; set; }
public int? TiD { get; set; }
public int? Rid { get; set; }
public DateTime? Udate { get; set; }
public string? Ipaddress { get; set; }
public int? Delid { get; set; }
public string? IStatus { get; set; }
public TimeSpan? UTime { get; set; }
public string? ICat { get; set; }
public string? IHot { get; set; }
public decimal? YPer { get; set; }
public int? WType { get; set; }
public virtual ICollection<Bigbalprd> Bigbalprds { get; set; } = new List<Bigbalprd>();
public virtual ICollection<CustomerItem> CustomerItems { get; set; } = new List<CustomerItem>();
public virtual Uom? IduomNavigation { get; set; }
public virtual Region? RidNavigation { get; set; }
public virtual Section? Sec { get; set; }
public virtual ItemType? TiDNavigation { get; set; }
[NotMapped]
public List<SelectListItem>? Listofsections { get; set; }
[NotMapped]
public List<SelectListItem>? Listofcategory { get; set; }
[DisplayName("Section")]
public string? Secnam { get; set; }
[DisplayName("Category")]
public string? Cname { get; set; }
}
View
@model IEnumerable<Used_Clothing_Managment.Models.ItemMasterFile>
@{
ViewBag.Title = "Item List";
}
<div class="card-body">
@* @Html.ActionLink("Create Department", "CreateDepartment", null, new { @class = "btn btn-primary" })*@
<a asp-action="Create" class="btn btn-primary" asp-controller="Items">
Create New
</a>
<hr />
<form asp-action="Create">
<div class="form-group">
<div class="alert-danger" asp-validation-summary="ModelOnly"></div>
<label asp-for="@Model.ToList()[0].SecId">Section</label>
<select asp-for="@Model.ToList()[0].SecId" class="form-select-sm form-control" data-live-search="true" asp-items="@(new SelectList(@Model.ToList()[0].Listofsections, "Value", "Text"))">
</select>
</div>
</form>
<div class="card-body">
<a asp-action="Create" class="btn btn-primary" asp-controller="Items">
Create New
</a>
<hr />
<table class="table table-striped my-4 w-100" id="datatable2">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.CodeItem)
</th>
<th>
@Html.DisplayNameFor(model => model.Descriptionitem)
</th>
<th>
@Html.DisplayNameFor(model => model.Secnam)
</th>
<th>
@Html.DisplayNameFor(model => model.Cname)
</th>
<th>
@Html.DisplayNameFor(model => model.BaleSize)
</th>
<th>
@Html.DisplayNameFor(model => model.Weight)
</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@if (Model != null && Model.Any())
{
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CodeItem)
</td>
<td>
@Html.DisplayFor(modelItem => item.Descriptionitem)
</td>
<td>
@Html.DisplayFor(modelItem => item.Secnam)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cname)
</td>
<td>
@Html.DisplayFor(modelItem => item.BaleSize)
</td>
<td>
@Html.DisplayFor(modelItem => item.Weight)
</td>
<td>
@* @Html.ActionLink("Edit", "Edit", new { dept_id = item.SecId }, new { @class = "btn btn-warning" }) |
@Html.ActionLink("Delete", "Delete", new { dept_id = item.SecId }, new { @class = "btn btn-danger" }) |
*@
<a asp-action="Edit" asp-route-id="@item.CodeItem" class="btn btn-warning">Edit</a> |
<a asp-action="Delete" asp-route-id="@item.CodeItem" class="btn btn-danger">Delete</a>
</td>
</tr>
}
}
else
{
<tr>
<td colspan="6">
<div>
No Employee Data is available..
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
@* <div>
<partial name="_GetItem" model="Model" />
</div>*@
</div>
Action Controller
public IActionResult ItemList()
{
var Itemlist = (from i in _context.ItemMasterFiles
join s in _context.Sections on i.SecId equals s.SecId
join c in _context.Catagories on i.Cid equals c.Cid
into ce
from sub in ce.DefaultIfEmpty()
where i.Packsize == "1" || i.Delid == null
select new ItemMV()
{
CodeItem = i.CodeItem,
Descriptionitem = i.Descriptionitem,
Secnam = s.Secnam,
BaleSize = i.BaleSize,
Weight = i.Weight,
Cname = sub.Cname,
}).ToList();
ItemMasterFile seclist = new ItemMasterFile();
var sectionList = (from s in _context.Sections
select new SelectListItem()
{
Text = s.Secnam,
Value = s.SecId.ToString()
}).ToList();
sectionList.Insert(0, new SelectListItem()
{
Text = "----Select----",
Value = string.Empty
});
seclist.Listofsections = sectionList;
return View(seclist);
}