There is something really strange going on in my MVC application that drives me crazy. On my MVC page, after the user has been selected, he should be twice "displayed" in HTML. Once in shape
FrmNextStep('<Login>', ... (where Model.SelectedUser.Login is used)
and once in the form
<input id="SelectedLogin" name="SelectedLogin" value="<Login>" type="hidden"> (where "Model".SelectedLogin is used)
but the second always remains empty. This is really strange because, despite the fact that the two calls do not match, the return value should be.
if (Model.SelectedUser != null) { <span>Some value</span> <script type="scriptADResultComplete"> @{ var script = String.Format( @"FrmNextStep('{0}', '{1}', '{2}');" , Model.SelectedUser.Login.Replace("'", @"\'") , Model.SelectedUser.FirstName.Replace("'", @"\'") , Model.SelectedUser.LastName.Replace("'", @"\'") ); @Html.Raw(script); } </script> } <input type="hidden" name="hfAction" /> <input type="hidden" name="hfUserLogin" /> @Html.HiddenFor(m => m.CurrentPage, new { id = "hfCurrentPage" }) @Html.HiddenFor(m => m.SelectedLogin); private User selectedUser; public User SelectedUser { get { if (this.selectedUser == null) { this.selectedUser = this.AllUsers.FirstOrDefault(user => user.Selected) ?? User.DefaultUser; } if (this.selectedUser == User.DefaultUser) { return null; } return this.selectedUser; } set { this.AllUsers.ForEach(user => user.Selected = (user == value)); this.selectedUser = null; } } public string SelectedLogin { get { return (this.SelectedUser ?? User.DefaultUser).Login; } set { this.SelectedUser = this.AllUsers.FirstOrDefault(user => user.Login == value); } }
And when I debug the code, this is the only call to Selected Login during the "rendering" phase and returns the correct login.
Is there an error with Html.HiddenFor?
Serge source share