Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc MVC 3详细信息视图强类型_Asp.net Mvc - Fatal编程技术网

Asp.net mvc MVC 3详细信息视图强类型

Asp.net mvc MVC 3详细信息视图强类型,asp.net-mvc,Asp.net Mvc,您好,我在获取我的产品的详细信息时遇到问题,代码Sneaker snkr=\u Sneaker\u categoryDataModel.sneakers.Find(id)似乎不起作用,它说.Find“不包含Find的定义” public class HomeController : Controller { // // GET: /Home/ private Forest.Models.ForestDBEntities _music_categoryDat

您好,我在获取我的产品的详细信息时遇到问题,代码
Sneaker snkr=\u Sneaker\u categoryDataModel.sneakers.Find(id)
似乎不起作用,它说
.Find
“不包含Find的定义”

public class HomeController : Controller
{
    //
    // GET: /Home/
    private Forest.Models.ForestDBEntities
        _music_categoryDataModel = new Forest.Models.ForestDBEntities();
    //private Models.music_categories music_categoryToCreate;
    public ActionResult Index()
    {
        IList<Forest.Models.music_categories> Categories = _music_categoryDataModel.music_categories.ToList<Forest.Models.music_categories>();
        return View("Categories",Categories);
    }

    public ActionResult Details (int id)
    {
        Sneaker snkr=_sneaker_categoryDataModel.sneakers.Find(id);

        return View(snkr);
    }
}
公共类HomeController:控制器
{
//
//回家/
private Forest.Models.ForestDBEntities
_music_categoryDataModel=新的Forest.Models.ForestDBEntities();
//私人模型。音乐类别音乐类别创建;
公共行动结果索引()
{
IList Categories=_music_categoritydatamodel.music_Categories.ToList();
返回视图(“类别”,类别);
}
公共行动结果详细信息(int id)
{
Sneaker snkr=\u Sneaker\u categoryDataModel.sneakers.Find(id);
返回视图(snkr);
}
}

\u sneaker\u categoryDataModel。sneakers
很可能是一个没有名为
Find
的方法的/。是
列表
上的一个方法,因此使用该方法的唯一方法是在
查找
之前调用
ToList()
(这可能会导致负面性能影响,具体取决于集合)

有各种各样的LINQ扩展,使得查询这些类型的集合变得微不足道,或者在这里是一个适当的选择

Sneaker snkr = _sneaker_categoryDataModel.sneakers.FirstOrDefault(x => x.Id == id);

是否包含System.Linq名称空间?是
使用System;使用System.Collections.Generic;使用System.Linq;使用System.Web;使用System.Web.Mvc;使用sneaker_info.Models
Find
不是LINQ扩展。只需使用
First()
Where()和First()
甚至
Single()
我仍然有同样的问题,但现在它的
x.Id
说“不包含查找的定义”@user3274859
x
代表了
运动鞋
,本例假设您有一个
Id
属性,如果没有,则需要在其所在位置使用相关属性。我怀疑您是否会看到该错误,因为此处没有使用
Find
。感谢您现在对我的帮助