'IEnumerable<ItemMV>' does not contain a definition for 'SecId' and no accessible extension method 'SecId' accepting a first argument of type 'IEnumerable<ItemMV>' could be found (are you missing a using directive or an assembly reference?

Analyst_SQL 3,576 Reputation points
2023-08-21T09:57:14.56+00:00

I am getting error ,when i am adding dropdown in view .

Model

    public class ItemMV
    {
        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; }

        [DisplayName("Section")]

        public string? Secnam { get; set; }


        [DisplayName("Category")]

        public string? Cname { get; set; }


        public string? Packsize { get; set; }

        public string? Alid { get; set; }

        public int? Iduom { get; set; }


        [NotMapped]

        public IEnumerable<SelectListItem>? Listofsections { get; set; }

    }


View

@model IEnumerable<Used_Clothing_Managment.Models.ListView.ItemMV>


@{
    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="SecId">Section</label>
            <select asp-for="SecId"
                    class="form-select-sm form-control" data-live-search="true"
                    asp-items="@(new SelectList(Model.Listofsections,"Value", "Text") )">
            </select>
        </div>
    }
    </form>


        <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>


ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JasonPan - MSFT 7,021 Reputation points Microsoft External Staff
    2023-08-22T08:28:16.4333333+00:00

    Hi @akhter hussain

    You don't have SecId in your select new ItemMV(), that's why you get the error.

     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()
                                {
                                    //******should add SecId here********//
                                    CodeItem = i.CodeItem,
                                    Descriptionitem = i.Descriptionitem,
                                    Secnam = s.Secnam,
                                 
                                    BaleSize = i.BaleSize,
                                    Weight = i.Weight,
                                    Cname = sub.Cname,
    
                                }).ToList();
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Jason

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.