我正在尝试创建一个 ViewModel 类。在“ViewModels”文件夹中创建类之后。无法识别我的 List 类型声明。我的问题和代码如下:
有人可以告诉我我错过了什么吗谢谢-P
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication8.ViewModels
{
//compiler does not recongize List class or SelectListitem
private List<SelectListItem> _products = new List<SelectListItem>();
//compiler does not recongize List class
public List<SelectListItem> products
{
get { return _products; }
}
}
最佳答案
Are there some special way of creating ViewModel Classes?
否 ,创建它们就像创建任何其他类一样。约定是将它们放在 中。型号 文件夹。
Are ViewModels a methodology, rather than a feature in MVC3?
种 .它们不是框架本身的功能,而是建议保持 View 的简单和干净,并简化模型绑定(bind)。
Can someone please tell me what I have missed thanks
你在哪里类声明?
namespace MvcApplication8.ViewModels
{
public class ThisIsTheClassNameAndMustGoFirst
关于asp.net-mvc-3 - MVC3 ViewModel 命名空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7072376/