-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAjaxExampleController.cs
More file actions
108 lines (93 loc) · 2.89 KB
/
AjaxExampleController.cs
File metadata and controls
108 lines (93 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using FeedbackMessages.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using WebApp.MVC.Models;
namespace WebApp.MVC.Controllers
{
/// <summary>
/// Ajax系サンプル
/// </summary>
public class AjaxExampleController : Controller
{
private List<ListExampleModel.User> UserList
{
get
{
return (List<ListExampleModel.User>)Session["AjaxExampleController.UserList"];
}
set
{
Session["AjaxExampleController.UserList"] = value;
}
}
// GET: AjaxExample
[HttpGet]
public ActionResult Index()
{
return View();
}
/// <summary>
/// ユーザーリストビューを描画します。
/// </summary>
/// <returns></returns>
[HttpPost]
public ActionResult PartialUserListView()
{
Thread.Sleep(1000 * 3);
if (UserList == null || UserList.Count == 0)
{
UserList = new List<ListExampleModel.User>
{
new ListExampleModel.User()
{
UserId = "001",
UserName = "ユーザーA",
Age = 20
},
new ListExampleModel.User()
{
UserId = "002",
UserName = "ユーザーB",
Age = 30
},
new ListExampleModel.User()
{
UserId = "003",
UserName = "ユーザーC",
Age = 40
}
};
}
var myViewData = new ViewDataDictionary(ViewData);
// WebApp.MVC.Models.ListExampleModel.UserList とマッピングできるようにプレフィックス指定
myViewData.TemplateInfo.HtmlFieldPrefix = "UserList";
myViewData.Model = UserList;
return new PartialViewResult
{
ViewData = myViewData,
ViewName = "_UserList",
TempData = TempData
};
}
/// <summary>
/// Postリクエストを処理します。
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public ActionResult Index(WebApp.MVC.Models.ListExampleModel model)
{
foreach (var user in model.UserList)
{
this.InfoMessage(user.UserId + ", " + user.UserName + ", " + user.Age);
}
// 編集内容キープ
UserList = model.UserList;
return View(model);
}
}
}