質問編集履歴

3

修正

2020/08/13 02:41

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -134,6 +134,52 @@
134
134
 
135
135
  }
136
136
 
137
+
138
+
139
+ function setSelect2(select2IdName, data, allowClear, disabled, tags, width) {
140
+
141
+ $(select2IdName).select2({
142
+
143
+ data: data,
144
+
145
+
146
+
147
+ // Select2 option here
148
+
149
+ allowClear: allowClear, // Clear button, default : true
150
+
151
+ disabled: disabled, // Disabled(display only), default : false
152
+
153
+ placeholder: "-- 選択 --", // Placeholder
154
+
155
+ tags: tags, // Dynamic input, default : false
156
+
157
+ width: width // 50% or 100%
158
+
159
+
160
+
161
+ // Do not open when clicking "x"
162
+
163
+ }).on("select2:unselecting", function (e) {
164
+
165
+ $(this).data("state", "unselected");
166
+
167
+ }).on("select2:open", function (e) {
168
+
169
+ if ($(this).data("state") === "unselected") {
170
+
171
+ $(this).removeData("state");
172
+
173
+ var self = $(this);
174
+
175
+ self.select2("close");
176
+
177
+ }
178
+
179
+ });
180
+
181
+ }
182
+
137
183
  ```
138
184
 
139
185
 

2

修正

2020/08/13 02:41

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -98,7 +98,7 @@
98
98
 
99
99
  $("#select2CategoryId").on("select2:unselecting", function (e) {
100
100
 
101
- $("#CategoryId").val(null);
101
+ $("#CategoryId").val(null); // または0に変更
102
102
 
103
103
  });
104
104
 

1

修正

2020/08/13 02:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  [Required(ErrorMessage = "{0} は選択が必須です。")]          // ← 有効にならない
28
28
 
29
- [Range(1, int.MaxValue, ErrorMessage = "{0} は選択が必須です。")]   // ← 有効にならない
29
+ [Range(1, int.MaxValue, ErrorMessage = "{0} は選択が必須です。")]   // ← 試してみたが有効にならない
30
30
 
31
31
  [Display(Name = "分類")]
32
32