0
我正在使用MVC 4.0
和entity-framework 5
生成model
。自動化索引視圖不能正常工作的自定義
餘米試圖瞭解定製的概念,我跟着教程的網站給予相同的this和this相同的步驟
唯一不同的是我加入在不同的子文件夾,這種定製類代碼,因爲當直接嘗試添加該在模型文件夾它顯示了在這個已經創建的錯誤員工類(由實體framwork autogenrated)
自動生成的代碼通過實體框架
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CustomizationConceptUmang.Models
{
using System;
using System.Collections.Generic;
public partial class employee
{
public int id { get; set; }
public string name { get; set; }
public string email { get; set; }
}
}
代碼定製
namespace CustomizationConceptUmang.Models.ViewModel
{
[MetadataType(typeof(employeeMetaData))]
public partial class employee
{
}
public class employeeMetaData
{
[Display(Name="Employee Name")]
public string name { get; set; }
}
}
查看
<th>
@Html.DisplayNameFor(model => model.name)
</th>
不過它顯示名,而不是員工姓名
請建議我如何提前解決此感謝。
從viewmodel的命名空間中移除'.ViewModel'。有關[MSDN:部分類和方法(C#編程指南)](https://msdn.microsoft.com/en-us/library/wa80x488.aspx)的更多詳細信息。 – CodeCaster