c# - Which is the best way to use multiple models with sames properties and using a unique view? -


for example, have 3 models id (int), name (string) , active (bool). it's possible use 1 view these models same properties ? technique generic object ? inheritance ? it's avoid write multiple views same html code.

you create viewmodel.

for sample:

public class customerviewmodel {    public int id { get; set; }    public string name { get; set; }    public bool active { get; set; } } 

and create viewmodel type this:

public class customersviewmodel {     public customerviewmodel customer1 { get; set; }     public customerviewmodel customer2 { get; set; }     public customerviewmodel customer3 { get; set; } } 

and type view type:

@model customersviewmodel 

or use collection type view

@model list<customerviewmodel> 

take @ anwser! https://stackoverflow.com/a/694179/316799


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -