SkyoceanHome
Home
Privacy
ダウンロード
SkyShop
Updated Information
チュートリアルコード集
References
記事編集
日付
ジャンルのカテゴリ―名
名前を選択して下さい。
Contexts
Controllers
Databases
Htmls
JavaScripts
Models
MVCTutorials
Others
Styles
Views
タイトル
内容の要旨
<p data-bm="12" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 4px; padding: revert; -webkit-line-clamp: revert; color: rgba(0, 0, 0, 0.8); font-family: roboto, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pasted="true">なるほど、やりたいことはこうですね。</p><ul data-bm="13" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; color: rgba(0, 0, 0, 0.8); font-family: roboto, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">ASP.NET Core MVC</strong> の CreateView に<ul style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">親 <code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"><select></code>(<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">PaymentTypeId</code>)</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">子 <code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"><select></code>(<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">PaymentMethodId</code>)</li></ul></li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">親に新しい項目を追加できる(SweetAlert2 で入力 → DB 保存 → 即反映)</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">子も同様に新しい項目を追加できる(SweetAlert2 で入力 → DB 保存 → 即反映)</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">親子は <strong style="font-weight: 700;">協調表示(親選択で子が絞り込み)</strong></li></ul><p data-bm="14" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 4px; padding: revert; -webkit-line-clamp: revert; color: rgba(0, 0, 0, 0.8); font-family: roboto, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">以下に <strong style="font-weight: 700;">完全動作するサンプル構成</strong> を示します。<br>(Entity Framework Core を使用、SweetAlert2 は CDN で読み込み)</p><h2 data-bm="15" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">1. モデル定義</h2><pre data-priority="2" data-bm="16" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="23" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(248, 244, 241);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(60, 81, 180);">Csharp</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(217, 223, 251); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(60, 81, 180) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;"><span style="color: rgb(106, 115, 125);">// Models/PaymentType.cs</span> <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">PaymentType</span> { <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span> Id { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">string</span> Name { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } = <span style="color: rgb(227, 98, 9);">string</span>.Empty; <span style="color: rgb(215, 58, 73);">public</span> ICollection<PaymentMethod> PaymentMethods { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } = <span style="color: rgb(215, 58, 73);">new</span> List<PaymentMethod>(); } <span style="color: rgb(106, 115, 125);">// Models/PaymentMethod.cs</span> <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">PaymentMethod</span> { <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span> Id { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">string</span> Name { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } = <span style="color: rgb(227, 98, 9);">string</span>.Empty; <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(227, 98, 9);">int</span> PaymentTypeId { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> PaymentType PaymentType { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } = <span style="color: rgb(0, 92, 197);">null</span>!; } </code></pre><h2 data-bm="17" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">2. DbContext</h2><pre data-priority="2" data-bm="18" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="24" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(248, 244, 241);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(60, 81, 180);">Csharp</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(217, 223, 251); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(60, 81, 180) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;"><span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">AppDbContext</span> : <span style="color: rgb(111, 66, 193);">DbContext</span> { <span style="color: rgb(215, 58, 73);">public</span> DbSet<PaymentType> PaymentTypes { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> DbSet<PaymentMethod> PaymentMethods { <span style="color: rgb(215, 58, 73);">get</span>; <span style="color: rgb(215, 58, 73);">set</span>; } <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(111, 66, 193);">AppDbContext</span>(DbContextOptions<AppDbContext> options) : <span style="color: rgb(111, 66, 193);">base</span>(options) { } } </code></pre><h2 data-bm="19" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">3. コントローラー</h2><pre data-priority="2" data-bm="20" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="25" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(248, 244, 241);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(60, 81, 180);">Csharp</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(217, 223, 251); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(60, 81, 180) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;"><span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(215, 58, 73);">class</span> <span style="color: rgb(111, 66, 193);">PaymentsController</span> : <span style="color: rgb(111, 66, 193);">Controller</span> { <span style="color: rgb(215, 58, 73);">private</span> <span style="color: rgb(215, 58, 73);">readonly</span> AppDbContext _context; <span style="color: rgb(215, 58, 73);">public</span> <span style="color: rgb(111, 66, 193);">PaymentsController</span>(AppDbContext context) { _context = context; } <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">Create</span>() { ViewData[<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span>] = <span style="color: rgb(215, 58, 73);">new</span> SelectList(_context.PaymentTypes, <span style="color: rgb(3, 47, 98);">"Id"</span>, <span style="color: rgb(3, 47, 98);">"Name"</span>); ViewData[<span style="color: rgb(3, 47, 98);">"PaymentMethodId"</span>] = <span style="color: rgb(215, 58, 73);">new</span> SelectList(Enumerable.Empty<SelectListItem>()); <span style="color: rgb(215, 58, 73);">return</span> View(); } [<span style="color: rgb(0, 92, 197);">HttpPost</span>] <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">Create</span>(<span style="color: rgb(227, 98, 9);">int</span> PaymentTypeId, <span style="color: rgb(227, 98, 9);">int</span> PaymentMethodId) { <span style="color: rgb(106, 115, 125);">// 保存処理(例: 注文や支払いレコード)</span> <span style="color: rgb(215, 58, 73);">return</span> RedirectToAction(<span style="color: rgb(215, 58, 73);">nameof</span>(Create)); } <span style="color: rgb(106, 115, 125);">// 親追加</span> [<span style="color: rgb(0, 92, 197);">HttpPost</span>] <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">AddPaymentType</span>(<span style="color: rgb(227, 98, 9);">string</span> name) { <span style="color: rgb(215, 58, 73);">if</span> (<span style="color: rgb(227, 98, 9);">string</span>.IsNullOrWhiteSpace(name)) <span style="color: rgb(215, 58, 73);">return</span> BadRequest(<span style="color: rgb(3, 47, 98);">"Name is required"</span>); <span style="color: rgb(215, 58, 73);">var</span> type = <span style="color: rgb(215, 58, 73);">new</span> PaymentType { Name = name }; _context.PaymentTypes.Add(type); _context.SaveChanges(); <span style="color: rgb(215, 58, 73);">return</span> Json(<span style="color: rgb(215, 58, 73);">new</span> { id = type.Id, name = type.Name }); } <span style="color: rgb(106, 115, 125);">// 子追加</span> [<span style="color: rgb(0, 92, 197);">HttpPost</span>] <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">AddPaymentMethod</span>(<span style="color: rgb(227, 98, 9);">int</span> paymentTypeId, <span style="color: rgb(227, 98, 9);">string</span> name) { <span style="color: rgb(215, 58, 73);">if</span> (<span style="color: rgb(227, 98, 9);">string</span>.IsNullOrWhiteSpace(name)) <span style="color: rgb(215, 58, 73);">return</span> BadRequest(<span style="color: rgb(3, 47, 98);">"Name is required"</span>); <span style="color: rgb(215, 58, 73);">var</span> method = <span style="color: rgb(215, 58, 73);">new</span> PaymentMethod { Name = name, PaymentTypeId = paymentTypeId }; _context.PaymentMethods.Add(method); _context.SaveChanges(); <span style="color: rgb(215, 58, 73);">return</span> Json(<span style="color: rgb(215, 58, 73);">new</span> { id = method.Id, name = method.Name }); } <span style="color: rgb(106, 115, 125);">// 子リスト取得</span> [<span style="color: rgb(0, 92, 197);">HttpGet</span>] <span style="color: rgb(215, 58, 73);">public</span> IActionResult <span style="color: rgb(111, 66, 193);">GetPaymentMethods</span>(<span style="color: rgb(227, 98, 9);">int</span> paymentTypeId) { <span style="color: rgb(215, 58, 73);">var</span> methods = _context.PaymentMethods .Where(m => m.PaymentTypeId == paymentTypeId) .Select(m => <span style="color: rgb(215, 58, 73);">new</span> { id = m.Id, name = m.Name }) .ToList(); <span style="color: rgb(215, 58, 73);">return</span> Json(methods); } } </code></pre><h2 data-bm="21" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; font: 22px / 24px roboto, helvetica, sans-serif; height: 32px; -webkit-line-clamp: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">4. Create.cshtml</h2><pre data-priority="2" data-bm="22" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; overflow: hidden; color: rgba(0, 0, 0, 0.8); font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div data-bm="26" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(248, 244, 241);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: normal !important; font-variant: normal !important; font-weight: 400 !important; font-stretch: 100% !important; line-height: 18px; font-family: roboto, helvetica, sans-serif !important; font-optical-sizing: auto !important; font-size-adjust: none !important; font-kerning: auto !important; font-feature-settings: normal !important; font-variation-settings: normal !important; font-language-override: normal !important; font-size: 16px; display: inline-block; color: rgb(60, 81, 180);">Html</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px roboto, helvetica, sans-serif; background-color: rgb(217, 223, 251); border: 1px solid rgba(0, 0, 0, 0); display: grid; grid-auto-flow: column; align-items: center; cursor: pointer; color: rgb(60, 81, 180) !important; text-decoration: none !important; border-radius: 9999px; block-size: 28px; gap: 2px; padding-inline: 10px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; max-inline-size: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: clip; max-block-size: calc(1lh); padding-inline: 2px;">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;">@{ ViewData["Title"] = "Create Payment"; } <<span style="color: rgb(34, 134, 58);">link</span> <span style="color: rgb(0, 92, 197);">rel</span>=<span style="color: rgb(3, 47, 98);">"stylesheet"</span> <span style="color: rgb(0, 92, 197);">href</span>=<span style="color: rgb(3, 47, 98);">"https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css"</span>> <<span style="color: rgb(34, 134, 58);">script</span> <span style="color: rgb(0, 92, 197);">src</span>=<span style="color: rgb(3, 47, 98);">"https://cdn.jsdelivr.net/npm/sweetalert2@11"</span>></<span style="color: rgb(34, 134, 58);">script</span>> <<span style="color: rgb(34, 134, 58);">form</span> <span style="color: rgb(0, 92, 197);">asp-action</span>=<span style="color: rgb(3, 47, 98);">"Create"</span> <span style="color: rgb(0, 92, 197);">method</span>=<span style="color: rgb(3, 47, 98);">"post"</span>> <<span style="color: rgb(34, 134, 58);">div</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"form-group"</span>> <<span style="color: rgb(34, 134, 58);">label</span>>Payment Type</<span style="color: rgb(34, 134, 58);">label</span>> <<span style="color: rgb(34, 134, 58);">div</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"input-group"</span>> <<span style="color: rgb(34, 134, 58);">select</span> <span style="color: rgb(0, 92, 197);">asp-for</span>=<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"form-control"</span> <span style="color: rgb(0, 92, 197);">asp-items</span>=<span style="color: rgb(3, 47, 98);">"@(ViewData["</span><span style="color: rgb(0, 92, 197);">PaymentTypeId</span>"] <span style="color: rgb(0, 92, 197);">as</span> <span style="color: rgb(0, 92, 197);">SelectList</span>)" <span style="color: rgb(0, 92, 197);">id</span>=<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span>></<span style="color: rgb(34, 134, 58);">select</span>> <<span style="color: rgb(34, 134, 58);">button</span> <span style="color: rgb(0, 92, 197);">type</span>=<span style="color: rgb(3, 47, 98);">"button"</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"btn btn-outline-primary"</span> <span style="color: rgb(0, 92, 197);">id</span>=<span style="color: rgb(3, 47, 98);">"btnAddType"</span>>+</<span style="color: rgb(34, 134, 58);">button</span>> </<span style="color: rgb(34, 134, 58);">div</span>> </<span style="color: rgb(34, 134, 58);">div</span>> <<span style="color: rgb(34, 134, 58);">div</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"form-group mt-3"</span>> <<span style="color: rgb(34, 134, 58);">label</span>>Payment Method</<span style="color: rgb(34, 134, 58);">label</span>> <<span style="color: rgb(34, 134, 58);">div</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"input-group"</span>> <<span style="color: rgb(34, 134, 58);">select</span> <span style="color: rgb(0, 92, 197);">asp-for</span>=<span style="color: rgb(3, 47, 98);">"PaymentMethodId"</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"form-control"</span> <span style="color: rgb(0, 92, 197);">asp-items</span>=<span style="color: rgb(3, 47, 98);">"@(ViewData["</span><span style="color: rgb(0, 92, 197);">PaymentMethodId</span>"] <span style="color: rgb(0, 92, 197);">as</span> <span style="color: rgb(0, 92, 197);">SelectList</span>)" <span style="color: rgb(0, 92, 197);">id</span>=<span style="color: rgb(3, 47, 98);">"PaymentMethodId"</span>></<span style="color: rgb(34, 134, 58);">select</span>> <<span style="color: rgb(34, 134, 58);">button</span> <span style="color: rgb(0, 92, 197);">type</span>=<span style="color: rgb(3, 47, 98);">"button"</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"btn btn-outline-primary"</span> <span style="color: rgb(0, 92, 197);">id</span>=<span style="color: rgb(3, 47, 98);">"btnAddMethod"</span>>+</<span style="color: rgb(34, 134, 58);">button</span>> </<span style="color: rgb(34, 134, 58);">div</span>> </<span style="color: rgb(34, 134, 58);">div</span>> <<span style="color: rgb(34, 134, 58);">button</span> <span style="color: rgb(0, 92, 197);">type</span>=<span style="color: rgb(3, 47, 98);">"submit"</span> <span style="color: rgb(0, 92, 197);">class</span>=<span style="color: rgb(3, 47, 98);">"btn btn-success mt-3"</span>>Save</<span style="color: rgb(34, 134, 58);">button</span>> </<span style="color: rgb(34, 134, 58);">form</span>> <<span style="color: rgb(34, 134, 58);">script</span>> <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span>).<span style="color: rgb(111, 66, 193);">addEventListener</span>(<span style="color: rgb(3, 47, 98);">"change"</span>, <span style="color: rgb(215, 58, 73);">function</span> () { <span style="color: rgb(215, 58, 73);">const</span> typeId = <span style="color: rgb(215, 58, 73);">this</span>.value; <span style="color: rgb(111, 66, 193);">fetch</span>(<span style="color: rgb(3, 47, 98);">`/Payments/GetPaymentMethods?paymentTypeId=<span style="color: rgb(36, 41, 46);">${typeId}</span>`</span>) .<span style="color: rgb(111, 66, 193);">then</span>(res => res.<span style="color: rgb(111, 66, 193);">json</span>()) .<span style="color: rgb(111, 66, 193);">then</span>(data => { <span style="color: rgb(215, 58, 73);">const</span> methodSelect = <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"PaymentMethodId"</span>); methodSelect.innerHTML = <span style="color: rgb(3, 47, 98);">""</span>; data.<span style="color: rgb(111, 66, 193);">forEach</span>(m => { methodSelect.innerHTML += <span style="color: rgb(3, 47, 98);">`<option value="<span style="color: rgb(36, 41, 46);">${m.id}</span>"><span style="color: rgb(36, 41, 46);">${m.name}</span></option>`</span>; }); }); }); <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"btnAddType"</span>).<span style="color: rgb(111, 66, 193);">addEventListener</span>(<span style="color: rgb(3, 47, 98);">"click"</span>, <span style="color: rgb(215, 58, 73);">function</span> () { <span style="color: rgb(111, 66, 193);">Swal</span>.<span style="color: rgb(111, 66, 193);">fire</span>({ <span style="color: rgb(0, 92, 197);">title</span>: <span style="color: rgb(3, 47, 98);">'新しいPayment Type'</span>, <span style="color: rgb(0, 92, 197);">input</span>: <span style="color: rgb(3, 47, 98);">'text'</span>, <span style="color: rgb(0, 92, 197);">inputPlaceholder</span>: <span style="color: rgb(3, 47, 98);">'Type name'</span>, <span style="color: rgb(0, 92, 197);">showCancelButton</span>: <span style="color: rgb(0, 92, 197);">true</span>, <span style="color: rgb(0, 92, 197);">confirmButtonText</span>: <span style="color: rgb(3, 47, 98);">'追加'</span> }).<span style="color: rgb(111, 66, 193);">then</span>(result => { <span style="color: rgb(215, 58, 73);">if</span> (result.isConfirmed && result.value.<span style="color: rgb(111, 66, 193);">trim</span>() !== <span style="color: rgb(3, 47, 98);">""</span>) { <span style="color: rgb(111, 66, 193);">fetch</span>(<span style="color: rgb(3, 47, 98);">'/Payments/AddPaymentType'</span>, { <span style="color: rgb(0, 92, 197);">method</span>: <span style="color: rgb(3, 47, 98);">'POST'</span>, <span style="color: rgb(0, 92, 197);">headers</span>: { <span style="color: rgb(3, 47, 98);">'Content-Type'</span>: <span style="color: rgb(3, 47, 98);">'application/x-www-form-urlencoded'</span> }, <span style="color: rgb(0, 92, 197);">body</span>: <span style="color: rgb(3, 47, 98);">`name=<span style="color: rgb(36, 41, 46);">${<span style="color: rgb(227, 98, 9);">encodeURIComponent</span>(result.value)}</span>`</span> }) .<span style="color: rgb(111, 66, 193);">then</span>(res => res.<span style="color: rgb(111, 66, 193);">json</span>()) .<span style="color: rgb(111, 66, 193);">then</span>(data => { <span style="color: rgb(215, 58, 73);">const</span> select = <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span>); <span style="color: rgb(215, 58, 73);">const</span> option = <span style="color: rgb(215, 58, 73);">new</span> <span style="color: rgb(111, 66, 193);">Option</span>(data.name, data.id, <span style="color: rgb(0, 92, 197);">true</span>, <span style="color: rgb(0, 92, 197);">true</span>); select.<span style="color: rgb(111, 66, 193);">add</span>(option); select.<span style="color: rgb(111, 66, 193);">dispatchEvent</span>(<span style="color: rgb(215, 58, 73);">new</span> <span style="color: rgb(111, 66, 193);">Event</span>(<span style="color: rgb(3, 47, 98);">'change'</span>)); <span style="color: rgb(106, 115, 125);">// 子更新</span> }); } }); }); <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"btnAddMethod"</span>).<span style="color: rgb(111, 66, 193);">addEventListener</span>(<span style="color: rgb(3, 47, 98);">"click"</span>, <span style="color: rgb(215, 58, 73);">function</span> () { <span style="color: rgb(215, 58, 73);">const</span> typeId = <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">"PaymentTypeId"</span>).value; <span style="color: rgb(215, 58, 73);">if</span> (!typeId) { <span style="color: rgb(111, 66, 193);">Swal</span>.<span style="color: rgb(111, 66, 193);">fire</span>(<span style="color: rgb(3, 47, 98);">'先にPayment Typeを選択してください'</span>); <span style="color: rgb(215, 58, 73);">return</span>; } <span style="color: rgb(111, 66, 193);">Swal</span>.<span style="color: rgb(111, 66, 193);">fire</span>({ <span style="color: rgb(0, 92, 197);">title</span>: <span style="color: rgb(3, 47, 98);">'新しいPayment Method'</span>, <span style="color: rgb(0, 92, 197);">input</span>: <span style="color: rgb(3, 47, 98);">'text'</span>, <span style="color: rgb(0, 92, 197);">inputPlaceholder</span>: <span style="color: rgb(3, 47, 98);">'Method name'</span>, <span style="color: rgb(0, 92, 197);">showCancelButton</span>: <span style="color: rgb(0, 92, 197);">true</span>, <span style="color: rgb(0, 92, 197);">confirmButtonText</span>: <span style="color: rgb(3, 47, 98);">'追加'</span> }).<span style="color: rgb(111, 66, 193);">then</span>(result => { <span style="color: rgb(215, 58, 73);">if</span> (result.isConfirmed && result.value.<span style="color: rgb(111, 66, 193);">trim</span>() !== <span style="color: rgb(3, 47, 98);">""</span>) { <span style="color: rgb(111, 66, 193);">fetch</span>(<span style="color: rgb(3, 47, 98);">'/Payments/AddPaymentMethod'</span>, { <span style="color: rgb(0, 92, 197);">method</span>: <span style="color: rgb(3, 47, 98);">'POST'</span>, <span style="color: rgb(0, 92, 197);">headers</span>: { <span style="color: rgb(3, 47, 98);">'Content-Type'</span>: <span style="color: rgb(3, 47, 98);">'application/x-www-form-urlencoded'</span> }, <span style="color: rgb(0, 92, 197);">body</span>: <span style="color: rgb(3, 47, 98);">`paymentTypeId=<span style="color: rgb(36, 41, 46);">${typeId}</span>&name=<span style="color: rgb(36, 41, 46);">${<span style="color: rgb(227, 98, 9);">encodeURIComponent</span>(result.value)}</span>`</span> }) .<span style="color: rgb(111, 66, 193);">then</span>(res => res.<span style="color: rgb(111, 66, 193);">json</span>()) .<span style="color: rgb(111, 66, 193);">then</span>(data => { <span style="color: rgb(215, 58, 73);">const</span></code></pre><p data-f-id="pbf" style="text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;">Powered by <a href="https://www.froala.com/wysiwyg-editor?pb=1" title="Froala Editor">Froala Editor</a></p>
コピーする
添付画像
画像を変更
Back to List
//検索文:Editor内でHTMLコードをコピーさせる