:
Controller code:
Code
Copy code The Code is as follows: public actionresult calendardisplay ()
{
BL. dateeventbl de = new BL. dateeventbl ();
// Obtain the date of the current day and convert it to the date format using JavaScript.
Datetimeformatinfo mydtfi = new cultureinfo ("En-us", false). datetimeformat;
String utctime = datetime. Now. tostring ("Mmm DD, yyyy hh: mm: SS", mydtfi );
Viewdata ["currentday"] = utctime;
// Obtain the date of the event in the current month
List <datetime> datehaveevent = de. gettimehaveevent (datetime. Now. Year, datetime. Now. month );
List <string> dates = datehaveevent. Select (u => U. tostring ("Mmm DD, yyyy hh: mm: SS", mydtfi). tolist ();
Viewdata ["dateshaveevent"] = dates;
// Obtain the event of the current day
List <BL. cdateevent> deinfos = de. getde (datetime. Now, new GUID ("00000000-0000-0000-0000-000000000001 "));
// Obtain the current week
BL. datespanbl DS = new BL. datespanbl ();
Int currentweek = Ds. getcurrentweek (datetime. Now, new GUID ("00000000-0000-0000-0000-000000000002 "));
Viewdata ["currentweek"] = currentweek;
Return view (deinfos );
}
Partialview (local view ):
Code Copy code The Code is as follows: <% @ Control Language = "C #" inherits = "system. Web. MVC. viewusercontrol <ienumerable <BL. cdateevent>" %>
<% String JSON = ""; List <string> dateshaveevent = viewdata ["dateshaveevent"] As list <string >;%>
<%
If (dateshaveevent! = NULL & dateshaveevent. Count> 0)
{
JSON = "[";
For (INT I = 0; I <dateshaveevent. Count; I ++)
{
If (I = dateshaveevent. Count-1)
{
JSON + = "{\" time \ ": \" "+ dateshaveevent. elementat (I) +" \ "}"; // The last item
}
Else
{
JSON + = "{\" time \ ": \" "+ dateshaveevent. elementat (I) + "\"},";//
}
}
JSON + = "]";
}
%>
<Div id = "datepicker"> </div>
<Br/>
Current week <span style = "color: red; font-size: 14px;"> <% = viewdata ["currentweek"] %> </span>
<Br/>
<% = Datetime. Now. tow.datestring () %>
<Br/>
<%
Foreach (VAR item in Model)
{
%>
<% = Html. encode (item. Content) %>
<%
}
%>
<Br/>
<Div id = "otherevent" style = "width: 300px;"> </div>
JavaScript (SCRIPT ):
Code Copy code The Code is as follows: // The current time conversion between the server and the client
VaR A = '<% = viewdata ["currentday"] %> ';
VaR B = date. parse ();
VaR servicedate = new date (B );
VaR clientdate = new date ();
VaR yearoffset = servicedate. getyear ()-clientdate. getyear ();
VaR monthoffset = servicedate. getmonth ()-clientdate. getmonth ();
VaR dayoffset = servicedate. getdate ()-clientdate. getdate ();
/// Obtain the date list
VaR jsn = eval ('<% = JSON %> ');
$ (Function (){
VaR Options = {
Prevtext: "last March January", // prompt text for redirecting TO THE PREVIOUS PAGE
Nexttext: 'August 11', // The prompt text to jump to the next page.
Mindate:-30,
Maxdate: 30,
Hideifnoprevnext: false,
Defaultdate: "+" + yearoffset + "Y +" + monthoffset + "m +" + dayoffset + "D ",
Beforeshowday: displaydayhaveevent, // display the operation before each date
Onselect: Select // select a date callback function
};
Function displaydayhaveevent (date ){
For (VAR I = 0; I <jsn. length; I ++ ){
VaR cc = date. parse (jsn [I]. time );
VaR time = new date (CC );
If (date. getmonth () = time. getmonth () & date. getdate () = time. getdate ()){
Return [true, ""]
}
}
Return [false, ""];
}
Function select (datetext, insT ){
$ ('# Otherevent'). Load ("http://www.jb51.net/Calendar/EventDetail? Date = "+ datetext );
Return false;
}
// Initialize the date Control
$ ('# Datepicker'). datepicker (options );
})