視圖內部 - >共享文件夾我有DateTime.ascx局部視圖;MVC2:Datepicker不能在編輯器模板中工作
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%:Html.TextBox("", (Model.HasValue ? Model.Value.ToLongDateString() : string.Empty),
new { @class = "datePicker" })%>
這在大多數我的應用程序得益於jQuery庫http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js和這段JavaScript代碼的;
// noWeekendsOrHolidays
// beforeShowDay: $.datepicker.noWeekends
$(function() {
$(".datePicker").datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-1:c+1', beforeShowDay: noWeekendsOrHolidays });
});
我有一個觀點如下;
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master"
Inherits="System.Web.Mvc.ViewPage<SHP.WebUI.Models.BankHolidayViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
BankHoliday
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("Create", "BankHoliday"))
{%>
<%: Html.AntiForgeryToken() %>
<h3>Bank Holiday Administration</h3>
<% if (TempData["UpdatedFlag"].ToString() == "True")
{ %>
<p class="success">At time <% Response.Write(DateTime.Now.ToString("T")); %> - Details have been successfully saved
</p>
<%}
else if (TempData["UpdatedFlag"].ToString() == "False")
{%>
<p class="error">At time <% Response.Write(DateTime.Now.ToString("T")); %> - ERROR! Invalid date entered has NOT been saved
</p>
<%} %>
<p>Select the year: <%: Html.DropDownListFor(model => model.SelectedYear, Model.YearList)%></p>
<fieldset>
<legend>Enter the bank holidays here:</legend>
<p><i>You can find the bank holiday dates on this <a target="_blank" href="http://www.year-planner-calendar.wanadoo.co.uk/">website</a>.</i> </p>
<table class="groupBorder">
<tr>
<th>Bank Holiday</th>
<th>Date</th>
<th>Notes</th>
</tr>
<%: Html.EditorFor(x => x.BankHolidays) %>
<tr>
<td colspan="3" style="padding-top:20px;text-align: center">
<input type="submit" value="Save" id="btnSubmit"/>
</td>
</tr>
</table>
</fieldset>
<% } %>
<script language="javascript" type="text/javascript">
$(function() {
$("#SelectedYear").change(function() {
var year = $("#SelectedYear").val();
$("#wholepage").load('<%:Url.Content(@"~/BankHoliday/Create/")%>' + year);
});
});
</script>
</asp:Content>
在這裏可以看到行:<%:Html.EditorFor(X => x.BankHolidays)%> 這具有相關聯的編輯器模板;
「%><tr>
<td><%: Model.T.BankHolidayDescription%>
<%: Html.HiddenFor(model => model.BH.BankHolidayId) %>
<%: Html.HiddenFor(model => model.T.BankHolidayTypeId) %>
</td>
<td><%: Html.EditorFor(model => model.BH.NullableBankHolidayDate)%></td>
<td><%: Html.EditorFor(model => model.BH.BankHolidayComment)%></td>
</tr>
日期選擇器必須適用於<%。Html.EditorFor(型號=> model.BH.NullableBankHolidayDate)%>
但是它不工作我點擊現場並沒有任何反應
當我按下F12鍵,進入開發工具,我找到用的DatePicker控件的HTML樣子。
<input name="BankHolidays[6].BH.NullableBankHolidayDate" class="datePicker hasDatepicker" id="BankHolidays_6__BH_NullableBankHolidayDate" type="text" jQuery1341928330742="131"/>
所以這個類已被分配到datePicker,所以肯定它應該工作?
你在談論http://jqueryui.com/demos/datepicker/? – LeftyX 2012-07-10 14:04:30
另外,您的選擇器如何定義應用datepicker?你使用'$('。datePicker')'? – Tejs 2012-07-10 14:08:02
是的,這是正確的 – arame3333 2012-07-10 14:08:42