这是我的界面
interface IBase
{
string MvrId { get; set; }
string IndividualFullName { get; set; }
string FirstHospitalCaseNumber { get; set; }
}
我有一个班级
public class AddMedicineModel:IBase
{
private MedicalVarianceEntities DbCtx = new MedicalVarianceEntities();
public AddMedicineModel(int MvrId)
{
Mvr Mvr = DbCtx.Mvrs.Find(MvrId);
this.MvrId = Mvr.PKMvrId.ToString();//for display purposes
IndividualFullName = Mvr.IndividualLastName
+ ", "
+ Mvr.IndividualFirstName;
FirstHospitalCaseNumber = Mvr.CaseNumber.ToString();
}
//IBASE INTERFACE IMPLEMENTATION
public string MvrId { get; set; }
public string IndividualFullName { get; set; }
public string FirstHospitalCaseNumber { get; set; }
}
这是我的部分观点!注意我的部分视图未附加到我的AddMedicineModel
因此,我无法将其与继承自IBase的其他模型重复使用。如何为许多模型制作可重复使用的局部视图。
@model MedicalVariance.Models.ViewModels.AddMedicineModel
@Html.DisplayFor(model => model.MvrId)
@Html.DisplayFor(model => model.IndividualFullName)
@Html.DisplayFor(model => model.FirstHospitalCaseNumber)
答案 0 :(得分:2)
将其声明为接受界面:
@model IBase
答案 1 :(得分:1)
你也可以拥有两全其美:
偏-AddMecicineModel.cshtml
@model MedicalVariance.Models.ViewModels.AddMedicineModel
@Html.DisplayFor(model => model.PropertyInAddMedicineModelNotInInterface)
@Html.Partial("Partial-IBase", Model)
偏-IBase.cshtml
@model IBase
@Html.DisplayFor(model => model.MvrId)
@Html.DisplayFor(model => model.IndividualFullName)
@Html.DisplayFor(model => model.FirstHospitalCaseNumber)