为了账号安全,请及时绑定邮箱和手机立即绑定

Viewmodel 失去了它的一些值

Viewmodel 失去了它的一些值

C#
泛舟湖上清波郎朗 2023-07-09 17:43:13
抱歉,如果这个问题已经有答案,但我找不到。提交表单时,我的ViewModel会丢失一些值。具体来说,错误对象会丢失其值。我不明白为什么。我没有任何东西可以覆盖它。我非常感谢我能得到的任何帮助。我尝试删除= new ...(),但这会使程序抛出错误不是对象的实例视图模型:namespace Vacation.ViewModels{    public class EditScheduleViewModel : BaseViewModel    {        public EditScheduleError Error { get; set; } = new EditScheduleError();        public string GotoSched { get; set; } = "";        public string GotoURL { get; set; } = "";        public string Title { get; set; } = "";        public bool isLast { get; set; } = false;        public User Employee { get; set; } = new User();        public int TotalWeeks { get; set; } = 2;        public Schedule ScheduleActive { get; set; } = new Schedule();        public DateTime LastSchedEndDate { get; set; }        public List<Schedule> ScheduleAll { get; set; } = new List<Schedule>();        public List<ScheduleDay> Days { get; set; } = new List<ScheduleDay>(new ScheduleDay[28]);        public List<int> ClinicIds { get; set; } = new List<int>(new int[28]);        public List<ClinicInfo> ClinicsList { get; set; } = new List<ClinicInfo>();        public EditScheduleViewModel ()        {            ProjectName = "Scheman";        }    }    public class EditScheduleError    {        public bool Overlaps { get; set; }        public EditScheduleOverlappingError OverlappingError { get; set; } = new EditScheduleOverlappingError();    }    public class EditScheduleOverlappingError    {        public bool OverlapsBefore { get; set; }        public bool OverlapsAfter { get; set; }        public int IdBefore { get; set; }        public int IdAfter { get; set; }        public EditScheduleOverlappingErrorResolutions Resolution { get; set; } = new EditScheduleOverlappingErrorResolutions();    }    public class EditScheduleOverlappingErrorResolutions    {        public bool ChangeThis { get; set; }        public bool ChangeOther { get; set; }    }}这不是控制器的全部部分...您需要更多吗?预期的行为是错误保持其值,即使在我提交了表单之后也是如此。
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

通过将其添加到视图中,它起作用了!由于某种原因我必须设置这些值......不确定为什么。但是嘿,只要它有效,对吧?:)


@Html.HiddenFor(x => x.MyError.Overlaps, new { @Value = Model.MyError.Overlaps })

        @Html.HiddenFor(x => x.MyError.OverlappingError.OverlapsAfter, new { @Value = Model.MyError.OverlappingError.OverlapsAfter })

        @Html.HiddenFor(x => x.MyError.OverlappingError.OverlapsBefore, new { @Value = Model.MyError.OverlappingError.OverlapsBefore })

        @Html.HiddenFor(x => x.MyError.OverlappingError.IdAfter, new { @Value = Model.MyError.OverlappingError.IdAfter })

        @Html.HiddenFor(x => x.MyError.OverlappingError.IdBefore, new { @Value = Model.MyError.OverlappingError.IdBefore })



查看完整回答
反对 回复 2023-07-09
  • 1 回答
  • 0 关注
  • 108 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信