2011-02-28 80 views
0

我添加的DateTime Datetime.ascx如何在mvc頁面中設置DateTime.ascx(Nerdinner編輯器模板)?

\查看\共享\ EditorTemplates \

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %> 
    <%= Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}",Model)) %> 
     <script type="text/javascript"> 
      $(function() { 
       $('#EventDate').datetime({ 
        userLang: 'en', 
        americanMode: true 
       }); 
      }); 
      </script> 

,我需要用它在我的DateFrom - 要Texbox。

<%@ Register src="../Shared/EditorTemplates/DateTime.ascx" tagname="DateTime" tagprefix="uc1" %> 
<p> 
     Please enter your Date Range Below. 
    </p> 
      <p> 
    Please enter your Date Range Below. 
</p> 
    <form method="post" action="<%= Html.AttributeEncode(Url.Action("List")) %>"> 
    <div> 
     <table cellpadding="2" cellspacing="0" class="vertical"> 
      <tr> 
       <th>Date From:</th> 
       <td><%= Html.TextBox("datefrom") %></td> 
      </tr> 
      <tr> 
       <th>Date To:</th> 
       <td><%= Html.TextBox("dateto")%></td> 
      </tr> 

      <tr> 
       <th></th> 
       <td><input type="submit" value="Show My Orders" /></td> 
      </tr> 
     </table> 
    </div> 
</form> 

我從Nerdinner得到了Datetime.ascx問候

感謝

+0

您是否使用過HTML Helper而不是用戶控件?請參閱http:// www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs – Daveo 2011-02-28 23:33:49

+0

除了Linkgoron提供的正確答案之外,JavaScript會做你想做的事情嗎? – 2011-02-28 23:38:28

+0

我從Nerdinner得到了Datetime.ascx – Crimsonland 2011-02-28 23:43:19

回答

1

您需要使用的,而不是Html.EditorForHtml.TextBox

順便說一句,你能甚至使用<%@寄存器MVC中的..%>語法?我只在ASP.NET WebForms中使用過它(儘管我現在只使用Razor,所以我的ASCX有點生疏)