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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:00:30+00:00 2026-05-27T12:00:30+00:00

Everything appears to work as expected except that when it returns back the Partial

  • 0

Everything appears to work as expected except that when it returns back the Partial with the model that has NAME = "foo" after it has inserted the object, it does not change the Name and PercentAlcohol text boxes with the values in the Model.

When I output @Model.Name in the header of the partial by the validation messages it properly shows "foo". But the form still says whatever was in the textboxes when it was submitted.

HTML

<div id="createBeerForm">
    @{Html.RenderPartial("CreatePartial", new BeerCreateModel());}
</div>

CreatePartial

@{
    AjaxOptions options = new AjaxOptions
    {
        HttpMethod = "Post",
        UpdateTargetId = "createBeerForm", 
        InsertionMode = InsertionMode.Replace
    };        
}

@using (Ajax.BeginForm("Create", "Beer", null, options, new { @class = "form-stacked" }))
{
    @Html.ValidationSummary(true, "You have errors. Fix them.")
    @Html.LabelFor(m => m.Name)
    <div>
        @Html.TextBoxFor(m => m.Name, new { @class = "xlarge" })  
        @Html.ValidationMessageFor(m => m.Name)
    </div>
    @Html.LabelFor(m => m.PercentAlcohol)
    <div>
        @Html.TextBoxFor(m => m.PercentAlcohol, new { @class = "xlarge" }) 
        @Html.ValidationMessageFor(m => m.PercentAlcohol)
    </div>
    <p>
        <input type="submit" value="Create Beer" />
    </p>
}

Controller

    [HttpPost]
    public ActionResult Create(BeerCreateModel model)
    {
        if (ModelState.IsValid)
        {
            //Add Beer to DB
            return PartialView("CreatePartial", new BeerCreateModel { Name = "foo"});
        }
        else
        {
            return PartialView("CreatePartial", model);
        }
    }
  • 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-27T12:00:31+00:00Added an answer on May 27, 2026 at 12:00 pm

    You must clear the modelstate if you intend to change values in your POST controller action. HTML helpers first look at the modelstate when binding and then at the model. So:

    [HttpPost]
    public ActionResult Create(BeerCreateModel model)
    {
        if (ModelState.IsValid)
        {
            //Add Beer to DB
    
            // Here you are modifying the value of the Name parameter
            // in your model. But this parameter is also in ModelState.
            // So if you want this change to reflect on the subsequent view you
            // need to either clear it from the modelstate
            ModelState.Remove("Name");
            return PartialView("CreatePartial", new BeerCreateModel { Name = "foo"});
        }
        else
        {
            return PartialView("CreatePartial", model);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've setup a simple TCP file transfer. Everything appears to work OK, except for
I've wrapped my wcf client in a IDisposable wrapper and everything appears to work
I have an object Foo that has an NSNumber property which is declared like
Used code first and everything appears to work apart from the below which also
I'm trying to get a DataGridComboBoxColumn working with my ViewModel. Everything appears to work
Everything I have read says that when making a managed stored procedure, to right
Everything I can find in linq for aggregation has a group by clause. How
Well, the conversion with as.double appears to work, but then adding a non-integral number
I just switched over to iOS 5 and everything appears to be working in
Everything inherits from object. It's the basis of inheritance. Everything can be implicitly cast

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.