Terry

Terry

  • NA
  • 148
  • 0

How to add a class of common properties in multiple Models ?

Mar 15 2015 1:14 PM

Hi, 


   For my ASP.NET WebForms Azure application, I currently have 2 Models & I have couple of queries in respect to adding other 2 Models :


1) Both new models that I want to add have several fields in common. I am thinking OOPS style and wish to create a class/Model namely "CommonFields" and add an object of that in these 2 Models. The Code for it I am thinking should be :

public class Inquiry
{
public Inquiry()
{}

    public string ClientId { get; set;  }
    public string ProjectName { get; set;  }

    public CommonFields Common_Fields { get; set; }

    public string Status { get; set; }
    public string Description { get; set; }

}

CommonFields contains just properties with respective tags like "Display", "Required", Validator, etc. I don't think the way I have added is the right way. I believe the way I am trying to add is not the right way. Searched alot for this, but couldn't get thru it.

2) In both these Models, I will need 1 or more fields of the existing models to populate in the dropbox in these models to create.

I couldn't get how to go thru this and make it work ! The 1st point is it possible. ASP supporting OOPS should be possible, can you tell how ?? Due to these queries am stuck and not able to create these Models. Please guide me.

Any help is highly appreciated.   

Thanks


Answers (2)