【问题标题】:Can't change datetime value in Razor server无法更改 Razor 服务器中的日期时间值
【发布时间】:2022-01-03 04:13:51
【问题描述】:

我无法更改日期时间值,因为我绑定了该值,如果我填写整个日期时间值,我的给定值设置为默认值。 Sum:我想更改表单中的值,但我认为绑定覆盖了我在那一刻的更改。

我的剃须刀页面前端代码:

<form>
    <div class="row">
        <div class="col-md-8">
            <div class="form-group">
                <label for="Description" class="control-label">Leírás</label>
                <input form="Description" class="form-control" @bind="@task.Description" />
            </div>
            <div class="form-group">
                <label for="Duration" class="control-label">Időtartam</label>
                <input form="Duration" class="form-control" @bind="@task.Duration" />
            </div>
            <div class="form-group">
                <label for="Parent" class="control-label">Szülő</label>
                <select @bind="task.ParentId" class="form-control">
                    <option value=""></option>
                    @foreach (var t in Tasks)
                    {
                        if (t.Description != task.Description)
                        {
                            <option value="@t.Id">
                                @t.Id - @t.Description
                            </option>
                        }
                    }
                </select>
            </div>
            <div class="form-group">
                <label for="Starttime" class="control-label">Kezdési idő</label>
                <input form="Starttime" class="form-control" type="datetime-local" @bind-value="@task.Starttime"/>
            </div>
        </div>
    </div>

我的模特:

 public class ScheduleTask : IOid
    {
        [Key]
        public int Id { get; set; }
        [Required, StringLength(100)]
        public string Description { get; set; }
        [Required]
        public int Duration { get; set; }
        public int? ParentId { get; set; }
        public DateTime? Starttime { get; set; }
        public DateTime? Finishtime { get; set; }
        public ICollection<Previoustask> Beforetasks { get; set; }
        public ICollection<Previoustask> Previoustasks { get; set; }
        public virtual ICollection<Taskhrdetail> Taskhrdetails { get; set; }
        public virtual ICollection<Taskordetail> Taskordetails { get; set; }
    }

每个绑定都运行良好,只有开始时间对我来说是不可更改的。

【问题讨论】:

    标签: c# asp.net-core razor


    【解决方案1】:

    尝试使用以下代码:

    <input form="Starttime" class="form-control" type="datetime-local" @value="@task.Starttime"
                           @onchange="@((ChangeEventArgs __e) => task.Starttime =DateTime.Parse( __e?.Value?.ToString()))" />
    

    如果输入值发生变化,该值将绑定到task.Starttime

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 2017-07-15
      • 2020-08-06
      • 2012-11-18
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多