-
Notifications
You must be signed in to change notification settings - Fork 56
/
ChangingContextTH.cshtml
52 lines (35 loc) · 1.79 KB
/
ChangingContextTH.cshtml
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
@model ParentViewModel
@{
ViewBag.Title = "Changing context";
var differentViewModel = new BasicViewModel { RequiredString = "Initial value" };
}
<h1>Changing the context of the model - Tag Helpers</h1>
<p><a asp-action="ChangingContext">HTML Helpers</a>.</p>
<p>There are three separate forms tied to three different post actions. Turn off JavaScript, clear all the text fields and hit each of the three submit buttons and also play with putting in values and submitting the values to see how they are bound back.</p>
@if (Context.Request.Method.ToUpperInvariant() == "POST")
{
if (ViewBag.Action == "PostDifferentModel")
{
differentViewModel = ViewBag.BoundModel;
}
<h2>Binding data</h2>
<ul>
<li><strong>Action:</strong> @ViewBag.Action</li>
<li><strong>Model type:</strong> @ViewBag.ModelType</li>
<li><strong>Model data:</strong> <pre>@ViewBag.BoundModelData</pre></li>
</ul>
}
<h2>Completely different model</h2>
<p><code><partial name="_FormAgainstDifferentModel" model="differentViewModel" /></code></p>
<partial name="_FormAgainstDifferentModel" model="differentViewModel" />
<h2>Sub model (binding to itself)</h2>
<p><code><partial name="_FormAgainstChildProperty" model="Model?.Child" /></code></p>
<partial name="_FormAgainstChildProperty" model="Model?.Child" />
<h2>Sub model (binding to parent)</h2>
<p><code><form-partial name="_FormPartialAgainstChildProperty" for="Child" /></code></p>
<chameleon-form action="@Url.Action("PostParentViewModel")?tagHelpers=true">
<form-partial name="_FormPartialAgainstChildProperty" for="Child"/>
<form-navigation>
<submit-button label="Submit" add-class="parent-model"/>
</form-navigation>
</chameleon-form>