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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:48:05+00:00 2026-05-15T09:48:05+00:00

If you have the following: Asp.Net MVC 2 project having object classes that define

  • 0

If you have the following:

  1. Asp.Net MVC 2 project having object classes that define view models.
  2. Serialize these models to the web browser client using JSON.
  3. Client adds information to the objects, like an Order Line on an Invoice.
  4. Client sends back the object to the server for processing.

Is there any way to share with the client a data contract for the JSON objects? I would really want to have the server create a Order using an Order factory, then send it to the client. The client adds order lines using the data contracts, and sends back the fully populated object as JSON.

I would really like to do the following in JavaScript at the client:

var order = myService.OrderFactory.GetNewClientOrderRequest();
order.description = "Some New Order";
var orderLine = myService.OrderFactory.GetNewClientOrderLine( order);
orderLine.setProductID( 1234);
orderLine.setQty( 1);
order.AddLine( orderLine);
if( order.SubmitOrder() == true) {
    //display confirmation
}

Any examples or web page links to Asp.Net MVC 2 would be very helpful.

  • 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-05-15T09:48:05+00:00Added an answer on May 15, 2026 at 9:48 am

    Well, given an example model:

    [DataContract]
    public class Item
    {
      [DataMember]
      public string Title { get; set; }
    }
    

    You could create an action filter which deserialises your objects from JSON:

    /// <summary>
    /// Deserialises a DataContract parameter from its JSON equivalence.
    /// </summary>
    public class JsonParameterFilter : ActionFilterAttribute
    {
      #region Properties
      /// <summary>
      /// Gets or sets the parameter name.
      /// </summary>
      public string Name { get; set; }
    
      /// <summary>
      /// Gets or sets the type of the parameter.
      /// </summary>
      public Type Type { get; set; }
      #endregion
    
      #region Methods
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
        var request = filterContext.HttpContext.Request;
    
        string contentType = request.ContentType;
        if (!string.IsNullOrEmpty(contentType) && contentType.ToLower().Contains("application/json")) 
        {
          var serialiser = new DataContractJsonSerializer(this.Type);
          var @object = serialiser.ReadObject(request.InputStream);
    
          filterContext.ActionParameters[Name] = @object;
        }
      }
      #endregion
    }
    

    And applied to your action:

    [JsonParameterFilter(Name = "item", Type = typeof(Item))]
    public ActionResult ProcessItem(Item item)
    {
      // Do stuff here
    
      return View();
    }
    

    What you need to make sure you do is post the data with the content type of “application/json”:

    var item = ItemFactory.GetNewItem();
    item.Title = "Something";
    
    var json = $.toJSON(item);
    $.ajax({
      contentType: "application/json; charset=utf-8"
      data: json,
      dataType: "json",
      type: "post",
      url: "Controller/Action",
    });
    

    Obviously your client-side library/script needs to be able to create an instance of a javascript object that can be deserialised as your server-side instance.

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

Sidebar

Related Questions

I have the following models in my ASP.NET MVC 3 project: public class Task
I have created the following project structure for my new asp.net mvc project any
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I have an ASP.NET MVC 3 project that I just created using the project
Given the following setup, I have three assemblies. Web (ASP.NET MVC 3.0 RC1) Models
I have the following compiled query added to my ASP.NET MVC 2 project (as
I have a Asp.net MVC 2 project. My start page has following link: http://localhost:2666/Home/Index?SomeID=4f62c452-4513-4dd0-b235-830d721815e4
I have the following url I need to support in my asp.net mvc project
We have a ASP.Net MVC project that runs fine on our developer machines. When

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.