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

  • Home
  • SEARCH
  • 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 8880565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:11:15+00:00 2026-06-14T20:11:15+00:00

I have a feeling this could be a basic question! I have a complex

  • 0

I have a feeling this could be a basic question!

I have a complex object ie a document object which contains properties that are lists of other objects. It has been created by deserializing some XML.

I would like to pass the entire Model to the View

Return ViewResult(MyDoc)

In the View some properties are edited. Control is then returned back to the Post Controller:

        [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(Document myDoc)

“myDoc” now just represents my Form’s fields. I suspect this is ModelBinding at work. So I guess I need to persist my complex object in a hidden field(example would be great) or as a session object. However I am a bit confused how my updated field gets merged back into the persisted object(hidden or session).

  • 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-14T20:11:16+00:00Added an answer on June 14, 2026 at 8:11 pm

    You are right, this is model binding at work.

    The binding occurs almost automatically when you use HtmlHelpers such as :

    @Html.TextboxFor(model => model.PropertyName)
    

    This line actually creates something a little bit like this :

    <input type="textbox" id="Modelobject_PropertyName" name="ModelObject.PropertyName" />
    

    Then when you submit your form, the DefaultModelBinder is able to deserialize the POST value and create and object of the given type (at least it will try), if it can’t find a corresponding entry, the property will be null and if an entry have no corresponding property, it will be ignored (unless you have other parameters).

    You can read this article it’s a little bit old, but it’s still pretty accurate.

    As an exemple:

    Let’s say you have a simple object :

    public class IndexModel
    {
        public string MyProperty { get; set; }
        public bool MyCheckbox { get; set; }
    }
    

    A simple controler :

    public class TestingController : Controller
    {
        [OutputCache(Duration=0, NoStore = true)]
        public ActionResult Index()
        {
            return View(new IndexModel { MyProperty = "hi" });
        }
    
        [HttpPost]
        [OutputCache(Duration=0, NoStore = true)]
        public ActionResult Index(IndexModel model)
        {
            model.MyProperty += "!";
            ModelState.Clear();
            return View(model);
        }
    }
    

    And a simple view :

    @model MvcApp.Models.IndexModel
    
    @using (Html.BeginForm())
    {
        <div>
            @Html.LabelFor(model => model.MyProperty)<p />
            @Html.TextBoxFor(model => model.MyProperty) 
        </div>
        <div>
            @Html.LabelFor(model => model.MyCheckbox)<p />
            @Html.CheckBoxFor(model => model.MyCheckbox)
        </div> 
    
        <input type="submit" />
    }
    

    You will see, when you submit the form, that the model is recreated completely.

    If you don’t want to display the actual value of a property, but still need it persisted:

    @Html.HiddenFor(model => model.MyProperty)
    

    This will generate a hidden field that will be posted back and, therefor, persisted.

    Happy coding !

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

Sidebar

Related Questions

I have a feeling that this is a code smell, and I could be
I have a feeling this is a stupid question but I can't find the
I have a feeling that this query is pretty easy to construct, I just
I have the feeling the answer to this question is no but I figured
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
I have a feeling this XML is not valid, can someone please explain why?
I'm maintaining a CMS where I have this feeling it was made in the
I have a feeling I'm going about this all wrong. But anyway. I have
I have a feeling I am completely borking this MySQL query but I'll ask
This doesn't make sense to me, but I have a feeling I saw a

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.