-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartialViewExampleController.cs
More file actions
105 lines (86 loc) · 2.61 KB
/
PartialViewExampleController.cs
File metadata and controls
105 lines (86 loc) · 2.61 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
using FeedbackMessages.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using WebApp.MVC.Models;
namespace WebApp.MVC.Controllers
{
/// <summary>
/// PartialViewフォームバインディングサンプル<br/>
/// <see cref="WebApp.MVC.Core.Extensions.HtmlHelperExtensions.RenderPartialFor{TModel, TProperty}(HtmlHelper{TModel}, string, System.Linq.Expressions.Expression{Func{TModel, TProperty}})"/>
/// </summary>
public class PartialViewExampleController : ExampleControllerBase
{
// GET: PartialViewExample
[HttpGet]
public ActionResult Index()
{
var model = new PartialViewExampleModel();
model.TimeList.Add(new TimeModel
{
Hour = 8,
Minute = 30
});
model.TimeList.Add(new TimeModel
{
Hour = 9,
Minute = 30
});
return View(model);
}
[HttpPost]
public ActionResult Index(PartialViewExampleModel model)
{
foreach (var time in model.TimeList)
{
this.InfoMessage(time.Hour + ":" + time.Minute);
}
return View(model);
}
[HttpGet]
public ActionResult Nested()
{
var root = new NestedPartialViewModel
{
Value = "1"
};
CreateChildModel(root, 2);
return View(root);
}
[HttpPost]
public ActionResult Nested(NestedPartialViewModel model)
{
Print(model, "");
return View(model);
}
private void CreateChildModel(NestedPartialViewModel model, int depth)
{
if (depth == 4)
{
return;
}
var rnd = new Random();
var childDepth = depth + 1;
for (int i = 0; i < Math.Max(1, rnd.Next(5)); i++)
{
var child = new NestedPartialViewModel();
model.Children.Add(child);
child.Value = model.Value + "_" + (i + 1);
child.Parent = model;
CreateChildModel(child, childDepth);
}
}
private void Print(NestedPartialViewModel model, string prefix)
{
this.InfoMessage(prefix + model.Value);
foreach (var child in model.Children)
{
Print(child, prefix + " ");
}
}
}
}