asp.net mvc4中model与Model的区别
寂寞沙洲 2013-09-14 02:51:42 Index.chhtml页面上:
@model IEnumerable<MvcApp.Models.Product>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
还有代码:
@foreach (var item in Model) {
而Edit.cshtml页面上,也有类似的代码:
@model MvcApp.Models.Product
@Html.EditorFor(model => model.Name)
@Html.DropDownListFor(model => model.Category, MvcApp.Code.SysFieldModels.GetSysField(Model), "请选择")
------------------
个人的理解:model仅仅声明类型,Model是从控制器传过来给View的数据。但发现这样理解有问题,因为Edit.cshtml页面上,有代码:
@Html.EditorFor(model => model.Name),从这句看,好像model也是传过来的数据。但下面又有:
@Html.DropDownListFor(model => model.Category, MvcApp.Code.SysFieldModels.GetSysField(Model), "请选择"),看这句,好像Model里也是传过来的数据?
GetSysField()方法的代码如下:
public static SelectList GetSysField(Product p)
{
SportsStoreDbContext db = new SportsStoreDbContext();
var c = db.Products.Select(x => x.Category).Distinct().OrderBy(x => x);
return new SelectList(c, p.Category);
}
困惑啊!!请高手详细解释!不胜感谢!