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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:31:06+00:00 2026-05-26T07:31:06+00:00

I am using a view model and a partial view to insert a row

  • 0

I am using a view model and a partial view to insert a row using AJAX. When a new row is inserted the ViewModel’s ID (AttributeDefinitionID) is set to zero. On save, the ID is updated and sent back out the view. However the helper that binds to ID seems to still have the old value.

View model

public class AttributeEntryViewModel
{
    public int AttributeDefinitionID { get; set; }

    [Required]
    [MaxLength(255, ErrorMessage = "Name must be less than 
                                    255 characters in length.")]
    public string Name { get; set; }
}

Partial view “_AttributeEntryPartial.cshtml”

@model ICMDB.ViewModels.AttributeEntryViewModel

<tr id ="@Model.AttributeDefinitionID" >
   @Html.HiddenFor(model => model.AttributeDefinitionID)

   <td>
      @Html.EditorFor(model => model.Name)
      @Html.ValidationMessageFor(model => model.Name)
   </td>
   <td>
      <a href="#" onclick="RemoveAttribute(@Model.AttributeDefinitionID); 
                           return false;">Remove</a>
   </td>
</tr>

For some reason, the Html Helper Html.HiddenFor doesn’t bind to the correct value and produces the following Html:

<tr id="40850">
    <input id="AttributeDefinitionID" type="hidden" value="0" 
           name="AttributeDefinitionID" data-val-required="The 
           AttributeDefinitionID field is required." data-val-number= "The 
           field AttributeDefinitionID must be a number." data-val="true">

You can see that it has inserted the ID correctly in the row tag (<tr id = "40850">) but not in the input tag (value="0"). That should read value="40850".

Any ideas? Is the Html Helper or the browser caching the value?

EDIT: The AJAX function AddAttribute simply calls a controller function of the same name and appends the resulting partial (the partial listed above) to a table:

function AddAttribute() {
   // and send it as AJAX request
   $.ajax({
      url: '@Url.Action("AddAttribute")',
      type: 'POST',
      cache: false,
      success: function (result) {
         // when the AJAX succeeds add result to the table
         $('#AttributesTable').append(result);
      }
   })
}

[HttpPost]
public ActionResult AddAttribute()
{
   var model = new AttributeEntryViewModel();
   return PartialView("_AttributeEntryPartial", 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-26T07:31:07+00:00Added an answer on May 26, 2026 at 7:31 am

    The reason for the differences has nothing to do with caching in the browser. The browser would cache your HTML page as a whole an not parts of that (more correct: The browser will not cache parts of the result of an HTTP request)

    Your problem is the difference of the value in the POST request compared to the value in the model. This is explained in depth in this post

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

Sidebar

Related Questions

I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application
I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
I am using ASP.NET MVC 2, and am using a view-model per view approach.
I am trying to re-call core-data in UITable using model view. I am in
I am using the Model-View-Presenter pattern for a web page. Should the presenter be
What's the pros and cons of using a Model-View-Controller model in building your application?
Question: How do send data to a view model when using command binding? So
I am using MVVM architecture. I have a usercontrol UC as a View Model
I'm using ASP.NET MVC 2 and here's the issue. My View Model looks something
Using Ruby/RoR - The year is a string in the model/view. How do I

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.