如何根据所选日期显示时间 [英] how to display time according to the date selected
本文介绍了如何根据所选日期显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在开发asp.net-mvc项目,我需要在下拉列表中显示已选择给用户的日期的可用时间。我正在使用完整日历来显示日期。可用时间存储在数据库中。这是我的观点
@ Html.LabelFor(model => model.date,htmlAttributes:new {@class =control-label col-md-2 })
@ Html.EditorFor(model => model.date,new {htmlAttributes = new {@class =form-control,id =datepicker}})
@ Html.ValidationMessageFor(model => model.date,,new {@class =text-danger})
@Html .LabelFor(model => model.time,htmlAttributes:new {@class =control-label col-md-2})
@ Html.DropDownList(time,null, - 选择时间 - ,htmlAttributes:new {@class =form-control})
@ Html.ValidationMessageFor(model => model.time,,new {@class =text-危险})
这是我的控制器
public ActionResult CreateBooking()
{
return View();
}
// POST:Booking / Create
[HttpPost]
public ActionResult CreateBooking(bookingPatient bo)
{
尝试
{
b.booking(bo);
System.Web.HttpContext.Current.Session [ date] = bo.date;
return RedirectToAction( 索引, 预订);
}
catch
{
return View();
}
}
这是我的商务舱
public 无效预订(bookingPatient模型)
{
使用( var bookpro = new BookingRepository())
{
if (model .BookingId == 0 )
{
预订_booking = 新预订
{
Date = model.date,
Time = model.time
};
bookpro.Insert(_booking);
System.Web.HttpContext.Current.Session [ bookingId] = _booking.BookingId ;
}
}
}
这是我的模型视图
public class bookingPatient
{
public int id {获得跨度>; set ; }
public DateTime date { get ; set ; }
public DateTime time { get ; set ; }
}
有人请指导我这方面。提前致谢
解决方案
ByMeans of Culture Info您可以根据自己的要求获取日期和时间。
https://msdn.microsoft.com/en-us/library/5hh873ya(v = VS.90 ).aspx [ ^ ]
i'm currently working on asp.net-mvc project for which i need to display available time in dropdownlist for the date that has been selected to the user. i'm using full calendar to display the date. Available time is store in the database. This is my view
@Html.LabelFor(model => model.date, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.date, new { htmlAttributes = new { @class = "form-control", id = "datepicker" } })
@Html.ValidationMessageFor(model => model.date, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.time, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownList("time", null, "--Select Time--", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.time, "", new { @class = "text-danger" })
this is my controller
public ActionResult CreateBooking()
{
return View();
}
// POST: Booking/Create
[HttpPost]
public ActionResult CreateBooking(bookingPatient bo)
{
try
{
b.booking(bo);
System.Web.HttpContext.Current.Session["date"] = bo.date;
return RedirectToAction("Index", "Booking");
}
catch
{
return View();
}
}
this is my business class
public void booking(bookingPatient model)
{
using (var bookpro = new BookingRepository())
{
if (model.BookingId == 0)
{
Booking _booking = new Booking
{
Date = model.date,
Time = model.time
};
bookpro.Insert(_booking);
System.Web.HttpContext.Current.Session["bookingId"] = _booking.BookingId;
}
}
}
this is my modelview
public class bookingPatient
{
public int id { get; set; }
public DateTime date{ get; set; }
public DateTime time { get; set; }
}
Someone please guide me in this regard. Thanks in advance
解决方案
ByMeans of Culture Info You can get the date and time as per your requirement.
https://msdn.microsoft.com/en-us/library/5hh873ya(v=vs.90).aspx[^]
这篇关于如何根据所选日期显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文