asp.net mvc - Viewmodel set up Aspt.net MVC 6 -
i'm having trouble understanding how implement viewmodel in asp.net mvc, have following tables:
form
id, data
report
id, formid, owner, category, status, submissiondate
reportvalues
id, reportid, title, value
i'm looking way display , edit report , reportvalues in 1 viewmodel reportvalues.reportid = report.id
reportvalues have multiple entries relate report.
i have had @ similiar questions on here , tried following tutorial ( http://techfunda.com/howto/262/list-data-using-viewmodel ) , coming empty handed.
if need more information let me know , in advance replies!
your view model nothing more class. can solve many ways, here's example.
create 3 classes would.
public class form { public int id { get; set; } public string data { get; set; } } public class reportvalues { public int id { get; set; } public int reportid { get; set; } public string title { get; set; } public string value { get; set; } } public class report { public int id { get; set; } public int formid { get; set; } public string owner { get; set; } public string category { get; set; } public string status { get; set; } public datetime submissiondate { get; set; } }
then, create viewmodel class include 3 above classes this.
public class reportviewmodel { public form form { get; set; } public reportvalues reportvalues { get; set; } public report report { get; set; } }
in view can access 3 classes , properties in controller. model.form.id
depending on data types, reportvalues
property of report
, that's entirely data structure. need populate classes using whatever method want (entity framework, ado, etc.) before can pass them view , use them.
Comments
Post a Comment