dates = Fri Dec 19 2014 12:00:00 GMT+0800 (台北標準時間)
var d = new Date(dates);
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();
alert(year + "/" + month + "/" + day)
輸出結果: 2014/12/19
2014年12月17日 星期三
2014年12月15日 星期一
[MVC] DropDownListFor用法
View
@Html.DropDownListFor(m => m.Week, new SelectList((System.Collections.IEnumerable)ViewData["WeekList"], "Value", "Text"))
Controller
public ActionResult RoomOpenDateSet()
{
ViewData["WeekList"] = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
}
Class
public List<SelectListItem> CreatWeekDropDownList(string roomListID)
{
List<SelectListItem> items = new List<SelectListItem>();
var query = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
foreach (var item in query)
{
items.Add(new SelectListItem { Text = Enum.GetName(typeof(WeekList), item.Week), Value = item.Week.ToString() });
}
return items;
}
傳回html版==============================================================
[HttpPost]
public ActionResult GetWeekList(string roomListid)
{
return Json(sf.CreatWeekDropDownList(roomListid));
}
public string CreatWeekDropDownList(string roomListID)
{
List<SelectListItem> items = new List<SelectListItem>();
StringBuilder result = new StringBuilder();
int _roomListID = Convert.ToInt32(des.DESDecrypt(roomListID, "a"));
var userList = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(_roomListID);
result.Append("<select id=\"Week\" name=\"Week\">");
result.Append("<option value=\"0\">==請選擇星期==</option>");
foreach (var item in userList)
{
result.Append("<option value=\"" + item.Week + "\">" + item.Week + "</option>");
}
result.Append("</select>");
return result.ToString();
}
JS
$.ajax({
url: '/SpaceControl/GetWeekList/',
type: 'post',
data: { roomListid: roomListID },
cache: false,
async: false,
success: function (res) {
alert(res);
$("#Weeks").html(res);
},
error: function (x, e) {
window.location.href = "/Share/ErrorPage?err=500";
}
});
=======================================================================
列舉
public enum WeekList
{
一 = 1,
二 = 2,
三 = 3,
四 = 4,
五 = 5,
六 = 6,
日 = 7
}
@Html.DropDownListFor(m => m.Week, new SelectList((System.Collections.IEnumerable)ViewData["WeekList"], "Value", "Text"))
Controller
public ActionResult RoomOpenDateSet()
{
ViewData["WeekList"] = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
}
Class
public List<SelectListItem> CreatWeekDropDownList(string roomListID)
{
List<SelectListItem> items = new List<SelectListItem>();
var query = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
foreach (var item in query)
{
items.Add(new SelectListItem { Text = Enum.GetName(typeof(WeekList), item.Week), Value = item.Week.ToString() });
}
return items;
}
傳回html版==============================================================
[HttpPost]
public ActionResult GetWeekList(string roomListid)
{
return Json(sf.CreatWeekDropDownList(roomListid));
}
public string CreatWeekDropDownList(string roomListID)
{
List<SelectListItem> items = new List<SelectListItem>();
StringBuilder result = new StringBuilder();
int _roomListID = Convert.ToInt32(des.DESDecrypt(roomListID, "a"));
var userList = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(_roomListID);
result.Append("<select id=\"Week\" name=\"Week\">");
result.Append("<option value=\"0\">==請選擇星期==</option>");
foreach (var item in userList)
{
result.Append("<option value=\"" + item.Week + "\">" + item.Week + "</option>");
}
result.Append("</select>");
return result.ToString();
}
JS
$.ajax({
url: '/SpaceControl/GetWeekList/',
type: 'post',
data: { roomListid: roomListID },
cache: false,
async: false,
success: function (res) {
alert(res);
$("#Weeks").html(res);
},
error: function (x, e) {
window.location.href = "/Share/ErrorPage?err=500";
}
});
=======================================================================
列舉
public enum WeekList
{
一 = 1,
二 = 2,
三 = 3,
四 = 4,
五 = 5,
六 = 6,
日 = 7
}
訂閱:
文章 (Atom)
Visual Studio JS intellisense 失效解決方式
試了好久,發現到工具>選項>IntelliCode js項目設定啟用,重新開啟VS就正常了! 後來發現是TypeScript3.2版有問題停用,使用4.3版的TypeScript即可
-
開啟記事本將以下程式碼貼入存成.bat @ECHO OFF set x=%date:~0,4%%date:~5,2%%date:~8,2% CD C:\Windows\System32\winevt\Logs COPY Application.evtx D:\bak\...
-
登入驗證時使用ValidateAntiForgeryToken只要返回上頁重新登入頁面會出現提供的反仿冒語彙基元是針對使用者 "XXX",但是目前的使用者是 ""。 請在登入頁判斷有無驗證成功即可 public ActionResul...
-
使用truncate table 時會出現 無法截斷資料表 'xxx',因為該資料表正由 FOREIGN KEY 條件約束參考解決方式 先刪除再重建自動編號即可。 DELETE table; DBCC CHECKIDENT('table'...