Viewmodel 失去了它的一些值

抱歉,如果这个问题已经有答案,但我找不到。


提交表单时,我的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; }

    }

}

这不是控制器的全部部分...您需要更多吗?


预期的行为是错误保持其值,即使在我提交了表单之后也是如此。


泛舟湖上清波郎朗
浏览 112回答 1
1回答

holdtom

通过将其添加到视图中,它起作用了!由于某种原因我必须设置这些值......不确定为什么。但是嘿,只要它有效,对吧?:)@Html.HiddenFor(x => x.MyError.Overlaps, new { @Value = Model.MyError.Overlaps })&nbsp; &nbsp; &nbsp; &nbsp; @Html.HiddenFor(x => x.MyError.OverlappingError.OverlapsAfter, new { @Value = Model.MyError.OverlappingError.OverlapsAfter })&nbsp; &nbsp; &nbsp; &nbsp; @Html.HiddenFor(x => x.MyError.OverlappingError.OverlapsBefore, new { @Value = Model.MyError.OverlappingError.OverlapsBefore })&nbsp; &nbsp; &nbsp; &nbsp; @Html.HiddenFor(x => x.MyError.OverlappingError.IdAfter, new { @Value = Model.MyError.OverlappingError.IdAfter })&nbsp; &nbsp; &nbsp; &nbsp; @Html.HiddenFor(x => x.MyError.OverlappingError.IdBefore, new { @Value = Model.MyError.OverlappingError.IdBefore })
打开App,查看更多内容
随时随地看视频慕课网APP