-1
先生在这个控制器这个控制器是它显示错误,请检查下面的代码。先生我正在做网格视图的代码,但它显示错误
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
ProductDetailModel obj = new ProductDetailModel();
obj.ProductList = ProductData("");
return View(obj);
}
[HttpPost]
public ActionResult SearchResult(string SearchKey)
{
ProductDetailModel obj = new ProductDetailModel();
obj.ProductList = ProductData(SearchKey);
string strTable = "";
strTable = strTable + "< table>< thead>< tr>< th>Id</ th ><th>Product_Name</ th >";
strTable = strTable + "<th>Product_Detail</ th ><th>price</th></ tr></ thead>< tbody>";
foreach (var item in obj.ProductList)
{
strTable = strTable + "<tr>";
strTable = strTable + "<td>" + item.Id + "</ td >";
strTable = strTable + "<td>" + item.Product_Name + "</ td >";
strTable = strTable + "<td>" + item.Product_Detail + "</ td >";
strTable = strTable + "< td>" + item.price + "</ td >";
strTable = strTable + "</ tr >";
}
strTable = strTable + "</ tbody ></ table >";
return View(strTable);
}
public List<product> ProductData(string SearchKey)
{
List<product> objProduct = new List<product>();
gridEntities objDemoEntities = new gridEntities();
var productItem = from data in objDemoEntities.grids
where SearchKey == "" ? true : data.Product_Details.Contains(SearchKey)
select data;
foreach (var item in productData)
{
objProduct.Add(new product
{
Id = item.Id,
Product_Name = item.Product_Name,
Product_Detail = item.Product_Details,
price = (int)item.price
});
}
return objProduct;
}
爵士这是错误 错误1 FOREACH不能在“方法组”操作。你打算调用'方法组'吗? C:\ Users \ anand.kumar \ Documents \ Visual Studio 2013 \ Projects \ grid01 \ grid01 \ Controllers \ HomeController.cs 58 17 grid01 错误2 foreach语句无法对'method group'类型的变量进行操作,因为'method group'会不包含'GetEnumerator'的公共定义C:\ Users \ anand.kumar \ Documents \ Visual Studio 2013 \ Projects \ grid01 \ grid01 \ Controllers \ HomeController.cs 58 17 grid01
什么是'ProductData'(看起来像它的方法,而不是一个属性) –
最有可能你需要用'productData()' –
这应该是产品而不是单一productdata –