Asp.net mvc 3 MVC3 ViewModel命名空间问题
我正在尝试创建ViewModel类。在我在“ViewModels”文件夹中创建类之后。无法识别我的列表类型声明。我的问题和代码如下:Asp.net mvc 3 MVC3 ViewModel命名空间问题,asp.net-mvc-3,namespaces,viewmodel,Asp.net Mvc 3,Namespaces,Viewmodel,我正在尝试创建ViewModel类。在我在“ViewModels”文件夹中创建类之后。无法识别我的列表类型声明。我的问题和代码如下: 是否有一些创建ViewModel类的特殊方法 ViewModels是MVC3中的一种方法,而不是一种功能吗 有人能告诉我我错过了什么吗 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespa
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; }
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
命名空间MVCAPApplication8.ViewModels
{
//编译器不会重新定义列表类或SelectListitem
私有列表_products=新列表();
//编译器不重新定义列表类
公开上市产品
{
获取{return\u products;}
}
}
是否有一些创建ViewModel类的特殊方法
否,像创建任何其他类一样创建它们。惯例是将它们放在Models文件夹中
ViewModels是MVC3中的一种方法,而不是一种功能吗
有点。它们不是框架本身的一个特性,而是保持视图的简单和干净,并简化模型绑定的建议
有人能告诉我我错过了什么吗谢谢
你的课程声明在哪里?
namespace MvcApplication8.ViewModels
{
public class ThisIsTheClassNameAndMustGoFirst
是否有一些创建ViewModel类的特殊方法
否,像创建任何其他类一样创建它们。惯例是将它们放在Models文件夹中
ViewModels是MVC3中的一种方法,而不是一种功能吗
有点。它们不是框架本身的一个特性,而是保持视图的简单和干净,并简化模型绑定的建议
有人能告诉我我错过了什么吗谢谢
你的课程声明在哪里?
namespace MvcApplication8.ViewModels
{
public class ThisIsTheClassNameAndMustGoFirst
namespace MvcApplication1.Models
{
public class WhateverNameYouWantModel
{
public string Foo { get; set; }
public string Bar { get; set; }
}
}
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class HelloController : Controller
{
public ActionResult Index()
{
return View(new WhateverNameYouWantModel());
}
}
}
@model MvcApplication1.Models.WhateverNameYouWantModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>hello world!</div>
</body>
</html>
@model mvcapapplication1.Models.whatevernameyouwant模型
@{
布局=空;
}
指数
你好,世界!
namespace MvcApplication1.Models
{
public class WhateverNameYouWantModel
{
public string Foo { get; set; }
public string Bar { get; set; }
}
}
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class HelloController : Controller
{
public ActionResult Index()
{
return View(new WhateverNameYouWantModel());
}
}
}
@model MvcApplication1.Models.WhateverNameYouWantModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>hello world!</div>
</body>
</html>
@model mvcapapplication1.Models.whatevernameyouwant模型
@{
布局=空;
}
指数
你好,世界!