1

I have the following models Patient Class:

public class Patient
{
    public int PatientID { get; set; }

    public virtual Salutation salutation { get; set; }
    public int SalutationID { get; set; }
    public string Surname { get; set; }
    public string Firstname { get; set; }
    [Display(Name = "Date of Birth")]
    [DisplayFormat(DataFormatString="{0:d}", ApplyFormatInEditMode=true)]
    public DateTime DOB { get; set; }
    public string RegNo { get; set; }
    public DateTime RegDate { get; set; }
    public string Occupation { get; set; }
}

VatalSigns Class

public class VitalSign
{
    public int VitalSignID { get; set; }
    public string Sign { get; set; }
    [Display(Name = "Lower Limit")]
    public int? LowerHold { get; set; }
    [Display(Name = "Upper Limit")]
    public int? UpperHold { get; set; }
    [Display(Name = "Unit Of Measurment")]
    public string Units { get; set; }
}

PV class that stores VitalSigns for each patient

public class PVSign
{

    public long PVSignId { get; set; }
    [Display(Name = "Patient")]
    public int PatientID { get; set; }
    public VitalSign VitalSigns { get; set; }
    //public IList<VitalSign> VitalSigns { get; set; }
    public Patient patient { get; set; }

}

Now the problem I have is that I have not been able to get display on one from to enter the details. I want to select the Patient and the different Vitals signs will appear and I will save the ones I need to the PVSign table.

I have tired all sorts of samples from the web. You can see from the code below, this is the index stub:

public ActionResult Index()
{
    var pVSigns = db.PVSigns.Include(p => p.patient).Include(p => p.PVSignId).Include(p => p.VitalSigns);
    //var pVSigns = from o in db.Patients join o2 in db.PVSigns
    //List<object> myModel = new List<object>();
    //myModel.Add(db.Patients.ToList());
    //myModel.Add(db.VitalSigns.ToList());

    //return View(myModel);
    return View(pVSigns.ToList());
}

How to I solve this issue. I am new to MVC, if it was Webforms, I would have been through with this project.

Thank you.

2
  • 3
    Have you tried creating a view model? Commented Apr 22, 2016 at 11:30
  • why not encapsulate all your models into one and then pass it? Commented Apr 22, 2016 at 12:30

2 Answers 2

9

There is no single answer(solution) to this(your) problem. It depends on how you want to design/build/achieve your solution. The simple, brute solution : Just have a view model as a wraper that has as his properties the classes(models) you made and work around that,

public class FullPatientDetailsViewModel
{
    public Patient { get; set;}
    public List<PVSign> PatientPvSigns { get; set;} // Patien PV Signs
}

Or use just a PatientViewModel and load his PVSigns async with Ajax. There is no simple best solution, it all depends about what do you want to achieve as a bigger picture.

Sign up to request clarification or add additional context in comments.

Comments

0

I've answered a similar question here. As Alexandru mentioned, the easiest and most straightforward way would be to wrap your models inside a ViewModel. You can read about other ways to implement this here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.