public ActionResult AffirmTime()
{
var start = Request["startDate"].ToString();
var end = Request["endDate"].ToString();
var weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string date = "";
string time = "";
string trid = "";
for (DateTime dt = Convert.ToDateTime(start); dt <= Convert.ToDateTime(end); dt = dt.AddDays(1))
{
time += weekdays[(int)dt.DayOfWeek] + ",";
int month = dt.Month;
int day = dt.Day;
string MonthDay = month.ToString() + "月" + day.ToString() + "日";
date += MonthDay + ",";
trid += "id"+month + day + ",";
}
time = time.TrimEnd(',');
date = date.TrimEnd(',');
trid = trid.TrimEnd(',');
return Json(new { success = "true", Date = date, Time = time,trid=trid },JsonRequestBehavior.AllowGet);
}
JS:
function onLoad(start,end) {
$.ajax({
url: "AffirmTime",
data: { startDate: start, endDate: end },
type: "get",
dataType: "Json",
cache: false,
async: false,
success: function (data) {
var date = data.Date.split(',');
var week = data.Time.split(',');
var trid = data.trid.split(',');
var tr = "";
var selDate = "";
for (var i = 0; i < date.length; i++) {
tr += "<tr id='" + trid[i] + "'><td>" + date[i] + "</td><td>" + week[i] + "</td><td>领导</td><td>手机</td><td>值班员</td><td><a href='#' οnclick=\"alterRow('" + trid[i] + "')\">修改</a></td></tr>";
selDate += "<option value='" + trid[i] + "'>" + date[i] + "</option>";
}
$('#tabOndutyList tr:not(:first)').empty();
$('#tabOndutyList').append(tr);
$('#selDate').append(selDate);
}
});