public class SectionQuestionsViewModel
{
public int MdsId { get; set; }
public int SectionId { get; set; }
public int PrevSectionId { get; set; }
public int NextSectionId { get; set; }
public SectionQuestionColl answers { get; set; }
}
The first time in, the Prev/Next values are {0,3}, when the user clicks on the next button, they get section 3. The code, all the way to the @Model in the view, shows that the Prev/Next are {2,4}, but when I look at the HTML, the values are still {0,3}.
ehcarleton
Member
33 Points
46 Posts
Html.HiddenFor() isn't updated correctly
May 25, 2012 08:05 PM|LINK
public class SectionQuestionsViewModel { public int MdsId { get; set; } public int SectionId { get; set; } public int PrevSectionId { get; set; } public int NextSectionId { get; set; } public SectionQuestionColl answers { get; set; } }And the razor code looks like this:
@using (Html.BeginForm(new { mdsId = @Model.MdsId, sectionId = @Model.SectionId})) { @Html.HiddenFor(x => x.PrevSectionId) @Html.HiddenFor(x => x.NextSectionId) @* ... snip ... *@ }The first time in, the Prev/Next values are {0,3}, when the user clicks on the next button, they get section 3. The code, all the way to the @Model in the view, shows that the Prev/Next are {2,4}, but when I look at the HTML, the values are still {0,3}.
What is going on?
Sam
ignatandrei
All-Star
135210 Points
21690 Posts
Moderator
MVP
Re: Html.HiddenFor() isn't updated correctly
May 25, 2012 08:38 PM|LINK
The form submit takes precedence over the modified in the action.
Please use ModelState.RemoveKey("PrevSectionId")