我是 asp.net MVC 的新手,正在尝试从我认为的 Controller 访问一些数据。这是我的代码:
public ActionResult Index(string subcategory)
{
List<Object> products = db.ListOfProducts(subcategory);
return View(products);
}
我知道在将 LIST 传递到 VIEW 之后,应该有一些方法可以访问 VIEW 中的数据,但我似乎无法弄清楚如何。 通常,当我基于模型创建 View 时,我知道通过使用模型对象我可以访问我需要的数据,但通常顶部有一个关于模型的定义,而在我的情况下没有。
那么如何在我的 View 中访问列表数据呢?
请您参考如下方法:
将其添加到 View 顶部以定义模型类型:
@model List<Object>
您可能需要将其命名为:
@using Systems.Collections.Generic;
@model List<Object>
或
@model Systems.Collections.Generic.List<Object>
