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 8400709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:37:44+00:00 2026-06-09T21:37:44+00:00

so i am trying to do a general return for all WebAPI calls to

  • 0

so i am trying to do a general return for all WebAPI calls to our MVC4 framework project.

The problem i am running into is that the type object cannot be serialized easily.

So our return structure is this…,

[DataContract]
class UiOutput {
    [DataMember("success")]
    public bool Success {get;set;};
    [DataMember("success")]
    public object Data {get;set;};
}

This way every time a call is made it returns if it was successful or not and the data. The data could be an array of Models or whatever. Obviously, this is an easy task in php, but we are not there 🙂

So i read that the problem i am having is this, Error Three from site http://www.johnsoer.com/blog/?tag=the-type-was-not-expected-use-the-xmlinclude-or-soapinclude-attribute-to-specify-types-that-are-not-known-statically.

So i wanted to make a generic super class that could fix this except for how would it handle an array of ViewModels?

[XmlInclude(typeof(MyAwesomeViewModel))]
class SuperType { }

EXAMPLE:

[DataContract]
class UiOutput {
    [DataMember("success")]
    public bool Success {get;set;};
    [DataMember("success")]
    public SuperType Data {get;set;};
}

This will help return say

[DataContract]
class MyAwesomeViewModel {
    [DataMember("awesome")]
    public bool Awesome {get;set;};
    [DataMember("viewModel")]
    public string ViewModel {get;set;};
}

But if i have a controller that wants to return an array of MyAwesomeViewModel, then i do not know what to do!

What i mean is if there is a controller like

class MyAwesomeController : ApiController {
    public UiOutput ByYear(int year) {
        MyAwesomeViewModel[] models = Rep.GetByYear(year);
        UiOutput output = new UiOutput();
        output.success = true;
        output.data = //Todo:  Is there a way to overcome?
    }
}
  • 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-09T21:37:45+00:00Added an answer on June 9, 2026 at 9:37 pm

    If you want a generic return value then use HttpResponseMessage and create a payload object that derives from HTTPContent.

    class MyAwesomeController : ApiController {
        public HttpResponseMessage ByYear(int year) {
            MyAwesomeViewModel[] models = Rep.GetByYear(year);
            return new HttpResponseMessage(statusGoesHere) { Content = GetUIContent(models) };
        }
    }
    
    class UIContent : HttpContent {
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a general function in F# that would return all
I'm trying to make a general framework function that makes any Drawable become highlighted
I'm currently trying to get into Java Web Development in general in Spring more
I'm trying to create a user defined function in Oracle that will return a
I'm trying to write a general function that i can pass an object to
I'm trying to understand the MVC pattern and I get the general idea that
I'm trying to return all entities where a given property is not empty. The
So I will describe what I am trying to doing general. I have customers(the
For general knowledge and entertainment purposes I am trying to add some behavoiur to
General use case I am trying to implement a basic shell. Description I need

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.