So I am really new to MVCs. I've been teaching myself for a project at work.
I am trying to print out my lists to my webpage from my SQL database for some inventory items and I keep getting this error:
"Cannot convert lambda expression to type 'string' because it is not a delegate type"
I know there are some forms indicating adding some using statements, I still have the issue even after trying some of the solutions.
My controller looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LinqApplication.Models;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Entity;
namespace LinqApplication.Controllers
{
public class InventoryItemController : Controller
{
// GET: InventoryItem
public ActionResult Index()
{
IM_importEntities import = new IM_importEntities(); //our object to work with
List<InventoryItem> items = import.inventory_items.Where(x => x.itemnum == "480-15").Select(x => new InventoryItem{itemnum =x.itemnum}).ToList(); //x commands
items.ToList().ForEach(x => Console.WriteLine(x.itemnum)); //foreach loop for items
return View(items.ToList());
}
}
}
And my view looks like this:
@model List<LinqApplication.Models.InventoryItem>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<table class="table">
<tr>
<th>
@Html.DisplayName(model => model.itemnum)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.itemnum)
</td>
</tr>
}
</table>
And the error is underlined at: @Html.DisplayFor(modelItem => item.itemnum)
Does anyone have any ideas on how to fix this?
Thank you in advance!