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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:54:02+00:00 2026-05-17T02:54:02+00:00

I have a PartialView strongly typed to a view model <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>

  • 0

I have a PartialView strongly typed to a view model

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>" %>

<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Edit", "Rate", FormMethod.Post))
{ %>
<%=Html.ValidationSummary() %>

<%=Html.HiddenFor(Model => Model.ParentID)%>
<%=Html.HiddenFor(Model => Model.ParentTypeID)%>
<%=Html.HiddenFor(Model => Model.ParentTypeDescription)%>
<%=Html.HiddenFor(Model => Model.RateID)%>

<div >
    <%=Html.LabelFor(Model => Model.RateValue)%>
    <%=Html.DisplayFor(Model => Model.RateValue) %>
</div>

<div>
    <%=Html.LabelFor(Model => Model.StartDate)%>
    <%=Html.DisplayFor(Model => Model.StartDate, new { @class = "date" })%>
   <%-- <%=Html.EditorFor(Model => Model.StartDate, new { @class = "date" })%>--%>
</div>

<div>
    <input type="submit" name="button" value="Edit"/>
</div>

Heres the viewmodel

public class RateControlEditViewModel
{
    /// <summary>The parent ID is the Rate ID for the Current record. </summary>
    [HiddenInput(DisplayValue = false)]
    public int ParentID { get; set; }

    /// <summary>The parent Type ID is the Type ID for the Current record. </summary>
    [HiddenInput (DisplayValue= false)]
    public int ParentTypeID { get; set; }

    [HiddenInput(DisplayValue = false)]
    public string ParentTypeDescription { get; set; }

    /// <summary>Rate ID for current record, may be null if adding new rate. </summary>
    [HiddenInput(DisplayValue = false)]
    public int? RateID { get; set; }

    /// <summary>Percentage VAT Rate to 2 decimal places. </summary>
    [DisplayName("VAT Rate (%)")]
    [Required(ErrorMessage ="Please Supply VAT Rate as percentage value")]
    [Range(typeof(Decimal), "0","100")]
    public decimal RateValue { get; set; }

    /// <summary>Start date from which this VAT Rate will be active, the start date will also be
    /// the same value for the previous records End Date to ensure there are no gaps in the Rate.</summary>
    [DisplayName("VAT Rate Start Date")]
    [DataType(DataType.Date)]
    [Required(ErrorMessage="Please Supply Start date from which this VAT rate will become active")]
    public DateTime? StartDate { get; set; }

}

And heres the Controller method…

  [ActionName("Edit")]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(string button, RateControlEditViewModel model)
    { // Do Stuff here 
    }

My problem is the object “RateControlEditViewModel model” passed into the controller has lost some of its values…
Basically screen one should show a list of objects, when you click “Edit” a new view should open displaying the 1 object you clicked on to allow you to edit it – but its losing the values.
Help!

  • 1 1 Answer
  • 4 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-17T02:54:03+00:00Added an answer on May 17, 2026 at 2:54 am

    Ok,
    It seems that if you are using “DisplayFor”, the model attributes aren’t populated.
    Using my example below, the values I receive back to the controller are those in the “HiddenFor” objects, but not those in the “DisplayFor”.

    <%=Html.HiddenFor(Model => Model.ParentID)%>
    <%=Html.HiddenFor(Model => Model.ParentTypeID)%>
    <%=Html.HiddenFor(Model => Model.ParentTypeDescription)%>
    <%=Html.HiddenFor(Model => Model.RateID)%>
    <div >
        <%=Html.LabelFor(Model => Model.RateValue)%>
        <%=Html.DisplayFor(Model => Model.RateValue) %>
    </div>
    
    <div>
        <%=Html.LabelFor(Model => Model.StartDate)%>
        <%=Html.DisplayFor(Model => Model.StartDate, new { @class = "date" })%>
    </div>
    

    To resolve this I just included “HiddenFor”s for the other 2 attributes 🙂

    <%=Html.HiddenFor(Model => Model.RateValue)%>
    <%=Html.HiddenFor(Model => Model.StartDate)%>
    

    Simple I think – hope it helps someone else.

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

Sidebar

Related Questions

If I have the below PartialView <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<Models.Photo> %> <% using (Html.BeginForm(MyAction,
Hi, I have a Strongly typed view in ASP.NET MVC. To keep track on
I have a strongly typed view, Edit, with a model named OrderModel. In this
I have a view that is not strongly typed. However I have in this
I have a strongly typed partial view CheckBox.ascx that renders a checkbox. This is
I have a strongly-typed Partial View that takes a ProductImage and when it is
I have the following MVC2 view that is strongly typed with a viewmodel, the
Ok I have a View thats is strongly typed as a collection of MyObject
I'm working on a strongly-typed edit form for a MVC model that contains a
I have a partial view which is not strongly typed. it is dynamic: <%@

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.