Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:17:04+00:00 2026-06-15T16:17:04+00:00

I have a big problem and I’m a little bit disappointed. I can’t find

  • 0

I have a big problem and I’m a little bit disappointed. I can’t find a good solution with this problem:

I have CompanyA and CompanyB who specialize Company who has an interface ICompany
in my controller. I then load from different databases, companyA and companyB in my List<company>. In my EditorView, I display the different objects companyA and companyB.

When I’m saving, in my controller, my objects in my list aren’t to type CompanyA and CompanyB, but they are all of type Company.

How can I keep my types when I save?

Here is some code if my explanation is not clear:

My example CompanyViewModel.cs:

public class CompanyViewModel
{
    #region Properties
    public User User { get; set; }
    public ExternalAccounts ExtAccounts { get; set; }
    public List<Company> Companies { get; set; } // or List<object> Companies { get; set; }
    ....
    #region Ctor
    public CompanyViewModel()
    { }
    public CompanyViewModel(ExternalAccounts extAccount, bool iniPrefLanguage = true)
    {
        //normaly it's load from bdd 
        ...
        Companies = new List<Company>();

        if (test == true)
        {
            Companies.Add(new CompanyA()); // call webService
        }
        if (test2 == true)
        {
            Companies.Add(new CompanyB());

        }
        ...
        #region
}

OR I can have:

    public ActionResult EditCompanies()
    {
        ...

        // Companies = new List<Company>();
         Model.Companies.Add(new CompanyA()); // call webService
         Model.Companies.Add(new CompanyB());                

        return View(Model);
    }

    public ActionResult SaveCompanies(ComapnyViewModel model)
    {
        var test = model.Companies.OfType<CompanyA>(); // return null !!!
        test = model.Companies.OfType<CompanyB>(); // return null !!!!
        test = model.Companies.OfType<Company>(); // return my objects !!!!

        return View();
    }

in view

       @Html.EditorFor(m => m.Companies)

and i have EditorTemplate with Company.cshtml, CompanyA.cshtml, CompanyB.cshtml

During my load in View, each object in my list go to the right EditorTemplate (CompanyA and CompanyB)

But when i save… I have a list of company type only …

Any ideas? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:17:05+00:00Added an answer on June 15, 2026 at 4:17 pm

    What I did is:

    I created a view with Company as model, and a partial view with CompanyA as model, and another view with CompanyB as model. Inside CompanyView, I called Html.Partial("CompanyAView", Model) and Html.Partial("CompanyBView", Model).

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big problem, since today. Before I could insert Guids into this
I have a big problem with this code and I have no idea how
i have a big problem... i have this map HashMap<Long, String> examValues; It gets
I have a big problem with my web site ( you can see here
I have a big problem opening http://localhost/ on Windows 7 (beta). I installed this
I have really big problem with calling JSON with jQueryUI autocomplete. I have this
I have a big problem with the fixtures bundle which I can't resolve. I
I have this big problem that i dont know how to fix. I have
I have big problem. I have 100000 rows in my database(sqlite). I can't reduce
I have a big problem, and I hope you can help me. I'm porting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.