0
我在創建用戶預訂應用程序時遇到了問題。基本上,除了最小值和最大值之類的基本屬性限制之外,我需要一個值來依賴另一個值。在我的應用程序中,用戶可以在湖邊預訂釣魚點。我需要它在整個小時內。例如,如果他們想在12:40開始捕魚,他們可以在13:40,14:40,15:40等結束。我該怎麼做? 我的模型看起來像這樣(Rezervaces是我在其中存儲用戶預約的對象):MVC用戶TimeSpan屬性限制和相互依賴
public partial class Rezervaces
{
public int RezId { get; set; }
public int UserId { get; set; }
public string UserPhone { get; set; }
[Required(ErrorMessage = "Time of start is required")]
public System.TimeSpan TimeStart{ get; set; }
[Required(ErrorMessage = "Time of finish is required")]
public System.TimeSpan TimeFinish{ get; set; }
[Required(ErrorMessage = "Date is required")]
[Range(DateTime.Now, DateTime.MaxValue)]
public System.DateTime DateDate{ get; set; }
}
和我的觀點的編輯是這樣的:
<divclass="form-group">
<bclass="control-labelcol-md-2">Timestart</b>
<divclass="col-md-10">
@Html.EditorFor(model=>model.TimeStart,new{htmlAttributes=
new{@class="form-control",@Value=
(DateTime.Now.AddMinutes(10)).TimeOfDay}})
@Html.ValidationMessageFor(model=>model.CasOd,"",new{
@class="text-danger"})
</div>
</div>
<divclass="form-group">
<bclass="control-labelcol-md-2">Timefinish</b>
<divclass="col-md-10">
@Html.EditorFor(model=>model.TimeFinish,new{htmlAttributes
=new{@class="form-control"},@Value=
(DateTime.Now.AddMinutes(10).AddHours(1)).TimeOfDay})
@Html.ValidationMessageFor(model=>model.CasDo,"",new{
@class="text-danger"})
</div>
</div>
<divclass="form-group">
<bclass="control-labelcol-md-2">Date</b>
<divclass="col-md-10">
@Html.EditorFor(model=>model.DateDate,new{htmlAttributes=
new{@class="form-control",@Value=DateTime.Now}})
@Html.ValidationMessageFor(model=>model.Datum,"",new{
@class="text-danger"})
</div>
</div>
<divclass="form-group">
<divclass="col-md-offset-2col-md-10">
<inputtype="submit"value="Addreservation"class="btnbtn-
default"style="background-color:darkseagreen;color:white"/>
</div>
</div>
任何幫助真的apprecited!謝謝!