任何人都知道在哪里可以找到一个html帮助器或者会产生由3个下拉列表组成的日期选择器的东西?
答案 0 :(得分:2)
这是我的小帮手。
我相信,它本身就是解释性的。可以调整以安排下拉菜单的顺序(月/日/年或日/月/年),如果您使用的是.NET 4,则可以为名称添加默认参数。编辑:删除文字以减少眼睛出血
/// <summary>
/// Creates a days, months, years drop down list using an HTML select control.
/// The parameters represent the value of the "name" attribute on the select control.
/// </summary>
/// <param name="dayName">"Name" attribute of the day drop down list.</param>
/// <param name="monthName">"Name" attribute of the month drop down list.</param>
/// <param name="yearName">"Name" attribute of the year drop down list.</param>
/// <returns></returns>
public static string DatePickerDropDowns(this HtmlHelper html, string dayName, string monthName, string yearName)
{
TagBuilder daysList = new TagBuilder("select");
TagBuilder monthsList = new TagBuilder("select");
TagBuilder yearsList = new TagBuilder("select");
daysList.Attributes.Add("name", dayName);
monthsList.Attributes.Add("name", monthName);
yearsList.Attributes.Add("name", yearName);
StringBuilder days = new StringBuilder();
StringBuilder months = new StringBuilder();
StringBuilder years = new StringBuilder();
int beginYear = DateTime.UtcNow.Year - 100;
int endYear = DateTime.UtcNow.Year;
for (int i = 1; i <= 31; i++)
days.AppendFormat("<option value='{0}'>{0}</option>", i);
for (int i = 1; i <= 12; i++)
months.AppendFormat("<option value='{0}'>{0}</option>", i);
for (int i = beginYear; i <= endYear; i++)
years.AppendFormat("<option value='{0}'>{0}</option>", i);
daysList.InnerHtml = days.ToString();
monthsList.InnerHtml = months.ToString();
yearsList.InnerHtml = years.ToString();
return string.Concat(daysList.ToString(), monthsList.ToString(), yearsList.ToString());
}
答案 1 :(得分:-1)
他们作为辅助方法工作,看起来很不错。例如,DatePicker的工作方式如下:
<%= Html.Telerik().DatePicker()
.Name("DatePicker")
.MinDate(Model.MinDate.Value)
.MaxDate(Model.MaxDate.Value)
.Value(Model.SelectedDate.Value)
.ShowButton(Model.ShowButton.Value)
%>