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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:10:59+00:00 2026-06-03T09:10:59+00:00

I am using Asp.net MVC 3 and Json.net library. I have view model class

  • 0

I am using Asp.net MVC 3 and Json.net library.

I have view model class called FranchiseInfo with a couple of properties.

public class FranchiseInfo
    {
        public string FolderName { get; set; }
        public string FullName { get; set; }

        public List<string> TestDropDown { get; set; }

        public void Initialize()
        {
            TestDropDown = new List<string>
                               {
                                   "Test1",
                                   "Test2"
                               };
        }

        public void SetDefaultValues()
        {
            FolderName = "SomeData";
            FullName = "SomeOtherData";
        }
    }

I have a controller FranchiseData which is serializing view model data to Json.

public ActionResult FranchiseData(string network)
        {
            JsonNetResult jsonNetResult = new JsonNetResult { Formatting = Formatting.Indented };

            FranchiseInfo franchiseInfo = new FranchiseInfo();

            franchiseInfo.Initialize();
            jsonNetResult.Data = franchiseInfo;

            return jsonNetResult;
        }

The controller has a single parameter called network. When the page first loads I want all the properties from the view model FranchiseInfo to be serialized and sent to the view. In that case the network value is null. So far, so good.

$.getJSON("Home/FranchiseData", function (data) {
  // get all FranchiseInfo properties
}

When a specific event occurs I am making a new request to the same FranchiseData controller passing network parameter which binds with the contoller parameter.

onTemplateChange = function (value) {
        var network = $("#networks :selected").val();
        $.getJSON("Home/FranchiseData", { network: network }, function (data) {
        // get only FolderName and  FullName properties
});
}

Now I want to call the SetDefaultValues() method of the Franchise Info view model class which sets default values to some of my properties and send only these properties back to the view.

So basically I am using the same contoller FranchiseData for serializing view model data from FranchiseInfo. When the parameter network is null, all the properties of FranchiseInfo should be serialized (FolderName, FullName and TestDropDown). When I call the controller againg and pass a value to the network parameter, I want to call the SetDefaultValues() method, set some properties and serialize only these properties again and send them to the server (FolderName and FullName only).
Is there a way to do this? Any help will be greatly appreciated. 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-03T09:11:00+00:00Added an answer on June 3, 2026 at 9:11 am

    Create a base class which contains the minimum amount of properties and inherit it.

    Send back the base class when you want to use the less amount of properties and the subclass otherwise.

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

Sidebar

Related Questions

I am using asp.net mvc with jquery... I have made a json call to
I'm using Asp.Net-Mvc, I have this method in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult LinkAccount(string
I am using ASP.NET MVC 3 with the razor view engine. I have the
i have the following code in c#. I'm using ASP.NET MVC 3. public override
I have something wrong with either json or ASP.NET MVC, I am using ASP.NET
I am attempting to use ASP.NET MVC 4 beta together with JSON.NET. I'm using
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET MVC 2.0, I have an actionlink that is used for comments on
I wrote an application using ASP.NET MVC, in this application I have an Index
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form

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.