質問編集履歴

5

修正

2022/04/28 04:46

投稿

corma
corma

スコア1

test CHANGED
File without changes
test CHANGED
@@ -29,6 +29,9 @@
29
29
  }
30
30
 
31
31
  var hpnm;
32
+ document.getElementById('hddiv').classList.remove("bkclrA");
33
+ document.getElementById('hddiv').classList.remove("bkclrB");
34
+ document.getElementById('hddiv').classList.remove("bkclrC");
32
35
  if (chgNo == '1')
33
36
  {
34
37
  document.getElementById('hddiv').classList.add("bkclrA");
@@ -43,12 +46,6 @@
43
46
  {
44
47
  document.getElementById('hddiv').classList.add("bkclrC");
45
48
  hpnm ="3333";
46
- }
47
- else
48
- {
49
- document.getElementById('hddiv').classList.remove("bkclrA");
50
- document.getElementById('hddiv').classList.remove("bkclrB");
51
- document.getElementById('hddiv').classList.remove("bkclrC");
52
49
  }
53
50
 
54
51
  return hpnm;

4

修正

2022/04/28 04:16

投稿

corma
corma

スコア1

test CHANGED
File without changes
test CHANGED
@@ -56,9 +56,9 @@
56
56
  </script>
57
57
  <div id="hddiv">
58
58
  <label id="rdoNm"></label>
59
- <input type="radio" name="rdo" id="rdo1" value="aaa" onchange="rdoChg()">aaa
59
+ <input type="radio" name="rdo" id="rdo1" value="1" onchange="rdoChg()">aaa
60
- <input type="radio" name="rdo" id="rdo2" value="bbb" onchange="rdoChg()">bbb
60
+ <input type="radio" name="rdo" id="rdo2" value="2" onchange="rdoChg()">bbb
61
- <input type="radio" name="rdo" id="rdo3" value="ccc" onchange="rdoChg()">ccc
61
+ <input type="radio" name="rdo" id="rdo3" value="3" onchange="rdoChg()">ccc
62
62
  </div>
63
63
  ```
64
64
 

3

追記

2022/04/28 04:15

投稿

corma
corma

スコア1

test CHANGED
File without changes
test CHANGED
@@ -63,6 +63,7 @@
63
63
  ```
64
64
 
65
65
  ```c#
66
+ //Index.cshtml.cs
66
67
  public void OnGet()
67
68
  {
68
69
  //ここで _Layout.cshtml の javascript の hpnm の値を取得したい。

2

コード追記

2022/04/28 04:14

投稿

corma
corma

スコア1

test CHANGED
@@ -1 +1 @@
1
- razor pages で Layout.cshtml の値を Index.cshtml.cs に渡す
1
+ razor pages で _Layout.cshtml の値を Index.cshtml.cs に渡す
test CHANGED
@@ -1,14 +1,74 @@
1
1
  ASP.NET core 6 razor pages で、
2
+ _Layout.cshtml のラジオボタンをクリックしたとき選択によって表示する値を変更し、
3
+ その値を Index.cs に渡し、且つ、Index側で処理が走っても _Layout.cshtml の表示されている値は保持したい。
4
+ ```html
2
- _Layout.cshtml (ヘッダ) に
5
+ <!-- _Layout.cshtml -->
6
+ <style type="text/css">
7
+ .bkclrA {
8
+ background-color: #0073b0;
9
+ }
3
10
 
11
+ .bkclrB {
4
- <label id="hgoe" >@ViewData["hoge"]</label>
12
+ background-color: #f7ca79;
13
+ }
5
14
 
15
+ .bkclrC {
16
+ background-color: #00a565;
17
+ }
18
+ </style>
19
+ <script type="text/javascript">
20
+ function rdoChg() {
6
- javascript
21
+ var chgNo;
22
+ let rdoval = document.getElementsByName('rdo');
23
+ let len = rdoval.length;
24
+ for (let i = 0; i < len; i++)
25
+ {
26
+ if (rdoval.item(i).checked) {
27
+ chgNo = rdoval.item(i).value;
28
+ }
29
+ }
7
30
 
31
+ var hpnm;
32
+ if (chgNo == '1')
33
+ {
8
- document.getElementById('hoge').innerText = "ほげ";
34
+ document.getElementById('hddiv').classList.add("bkclrA");
35
+ hpnm ="1111";
36
+ }
37
+ else if (chgNo == '2')
38
+ {
39
+ document.getElementById('hddiv').classList.add("bkclrB");
40
+ hpnm ="2222";
41
+ }
42
+ else if (chgNo == '3')
43
+ {
44
+ document.getElementById('hddiv').classList.add("bkclrC");
45
+ hpnm ="3333";
46
+ }
47
+ else
48
+ {
49
+ document.getElementById('hddiv').classList.remove("bkclrA");
50
+ document.getElementById('hddiv').classList.remove("bkclrB");
51
+ document.getElementById('hddiv').classList.remove("bkclrC");
52
+ }
9
53
 
10
- としたとき、
54
+ return hpnm;
55
+ }
56
+ </script>
57
+ <div id="hddiv">
11
- label に表示された "ほげ" という文字列を ViewData["hoge"] に入れて
58
+ <label id="rdoNm"></label>
59
+ <input type="radio" name="rdo" id="rdo1" value="aaa" onchange="rdoChg()">aaa
60
+ <input type="radio" name="rdo" id="rdo2" value="bbb" onchange="rdoChg()">bbb
12
- Index.cshtml.cs で受け取りたいのですが、うまくいきません。
61
+ <input type="radio" name="rdo" id="rdo3" value="ccc" onchange="rdoChg()">ccc
13
- 何か方法はあるのでしょうか?
62
+ </div>
63
+ ```
14
64
 
65
+ ```c#
66
+ public void OnGet()
67
+ {
68
+ //ここで _Layout.cshtml の javascript の hpnm の値を取得したい。
69
+ //OnGet() が難しければ他のイベント時に取得したい
70
+ }
71
+ ```
72
+
73
+ 以上、宜しくお願いします。
74
+

1

不要タグ削除

2022/04/28 02:28

投稿

corma
corma

スコア1

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,4 @@
11
11
  label に表示された "ほげ" という文字列を ViewData["hoge"] に入れて
12
12
  Index.cshtml.cs で受け取りたいのですが、うまくいきません。
13
13
  何か方法はあるのでしょうか?
14
+