0

这是我的界面

    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)
4

2 回答 2

2

只需将其声明为采用接口即可:

@model IBase
于 2012-05-30T15:39:30.803 回答
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)
于 2012-05-30T15:44:38.673 回答