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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:19:30+00:00 2026-05-17T06:19:30+00:00

I am creating a site in which I utilize partial views to display various

  • 0

I am creating a site in which I utilize partial views to display various bits of data about a single Model. Here is a bit of the HTML. (Note, all of these are contained within a single form and the Index page that these partials are rendered in is strongly typed to the main model. The main model contains various lists of data.)

<div id="tab1"><% Html.RenderPartial("Tab1", Model); %></div>
<div id="tab2"><% Html.RenderPartial("Tab2", Model.AnItemList1.FirstOrDefault<AnItemList1>()); %></div>
<div id="tab3"><% Html.RenderPartial("Tab3", Model.AnItemList2.FirstOrDefault()); %></div>

Here is ONE of the partial views headers (for ‘tab2’):

<%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<AnItem1>" %>

The pages display correctly. The issue is that, when I enter data into the various parts of the partial pages and then submit the entire form (via POST), the data is not making it back to my data store (MSSQL) – but this only happens for any of the list items (that are contained within the Model). The first partial page does properly have its data set within the data store.

What am I doing wrong here? Should I only be passing the model to Html.RenderPartial and then get the specific model I need on the partial page? Should I pass the entire list and then get the first (right now, I only care about the first item in the list – that will EVENTUALLY change, but not any time soon).

Suggestions or thoughts appreciated.

Update: Here is how I accessing the properties on the partial views.

<div class="data-group">
    <%: Html.CheckBoxFor(model => model.Property1) %>
    <%: Html.LabelFor(model => model.Property1) %>
</div> 

Update 2: Per request…

Controller Action (ScenarioController):

    public ActionResult Index(int id = 0)
    {
        if (id == 0)
        {
            SavedScenario scenario = new SavedScenario();
            scenario.AnItemList1.Add(new AnItem1());
            scenario.AnItemList2.Add(new AnItem2());
            return View("Index", scenario);
        }
        else
        {
            SavedScenario scenario = repository.GetScenario(id);

            if (scenario == null)
                return View("NotFound");
            else
                return View("Index", scenario);
        }
    }

    [HttpPost]
    public ActionResult Index(SavedScenario scenario)
    {
        if (ModelState.IsValid && TryUpdateModel(scenario, "SaveScenario"))
        {
            repository.Add(scenario);
            repository.Save();
        }

        return View(scenario);
    }

Rendered HTML (I can only include parts of it – this is a small sample of what is in the form):

<form action="/Scenario" id="form0" method="post">
    <!-- This is the one that works - the basic Scenario. Top level. -->
  <fieldset>
    <legend>Scenario Information</legend>

    <div class="data-group">
        <div class="editor-label">
            <label for="ScenarioName">Scenario Name</label>

        </div>
        <div class="option1">
            <input class="wide" id="ScenarioName" name="ScenarioName" type="text" value="" />
        </div>
        <div class="validation">
            <div><span class="field-validation-valid" id="ScenarioName_validationMessage"></span></div>
        </div>
    </div>
  </fieldset>   

<!-- This does not work or get submitted (as far as I can tell). -->
<div id="tab2">
<fieldset>
    <legend>Tab2</legend>
    <div class="data-group">
        <input id="Property1" name="Property1" type="checkbox" value="true" /><input name="Property1" type="hidden" value="false" />
        <label for="Property1" />
    </div> 
</div>
</fieldset>

</form>

My apologies for having to keep this so generic.

  • 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-17T06:19:32+00:00Added an answer on May 17, 2026 at 6:19 am

    Hard to guess from this much code. However you should make sure that all properties of your models have the same prefix when they are posted back to the server

    Edit: form field names should match property names of your model to correctly bind all values. You have two fields with the same name that you can bind in following way

    [HttpPost]
        public ActionResult Index(SavedScenario scenario, List<bool> Property1)
        {
            // here you can do with values coming in property1
            if (ModelState.IsValid && TryUpdateModel(scenario, "SaveScenario"))
            {
                repository.Add(scenario);
                repository.Save();
            }
    
            return View(scenario);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.