こんにちわ!
https://teratail.com/questions/165936の発展形になるかと思いますが、前回HtmlヘルパーのIdForを利用し、ボタンクリックでそのボタンと同じテーブルにあるエディタに文字列を挿入しました。
今回は画面上部の一括入力ボタンを押して、平日のみ定時の開始、終了、休憩時間を挿入するようにしたいです。
しかし前回と異なるのが、1つのボタンに対し、平日判定された可変複数のEditboxに値を挿入する必要があり、どうしたらいいか悩んでいます。
ちなみに平日判定はビューの日付表示のところで行っています。是非何かアドバイスをお願いします。
ビュー:
@model Kintai_CS_.Models.KintaiModel @{ /**/ ViewBag.Title = "勤務表"; Layout = "~/Views/Shared/_Layout.cshtml"; Dictionary<int, SelectList> dictionary = (Dictionary<int, SelectList>)ViewBag.Situation; } @using (Html.BeginForm()) { @Html.AntiForgeryToken() <header id="header" class="header"> ・・・ <div> <button type="button" class="btn btn-primary" style="margin-right:5px;width:120px">ユーザ管理</button> <button type="button" class="btn btn-primary" style="margin-right:5px;width:100px">履歴表示</button> @{ if (Model.MonthlyData.flag == "入力中") { <button type="button" class="btn btn-primary" style="margin-right:5px;width:100px">一括入力</button> <button type="submit" name="lastMonth" class="btn btn-primary" style="margin-right:5px;width:80px">前月</button> <button type="submit" name="nextMonth" class="btn btn-primary" style="margin-right:5px;width:80px">翌月</button> <button type="submit" name="update" class="btn btn-primary" style="margin-right:5px;width:80px">更新</button> <button type="button" class="btn btn-primary" style="width:100px">承認依頼</button> } else { ・・・ } } </div> </header> <body id="body" class="body"> ・・・ <table class="table"> <tr> <th> <nobr>日付</nobr> </th> <th> <nobr>曜日</nobr> </th> <th style="text-align:center"> <nobr>始業時刻</nobr> </th> <th style="text-align:center"> <nobr>終業時刻</nobr> </th> <th style="text-align:center"> <nobr>休憩時間</nobr> </th> <th> <nobr>所定時間</nobr> </th> <th> <nobr>残業時間</nobr> </th> <th style="text-align:center"> <nobr>勤怠状況</nobr> </th> <th style="text-align:center"> <nobr>補助</nobr> </th> <th style="text-align:center"> <nobr>備考</nobr> </th> </tr> @for (int idx = 0; idx < Model.Kintais.Count; idx++) { <tr> @*土は青、日祝は赤にする*@ @{ string week = Model.Kintais[idx].Date.ToString("ddd"); bool PublicHoliday = false; for (int i = 0; i < Model.Public_holidays.Count(); i++) { if (Model.Kintais[idx].Date == Model.Public_holidays[i].Date) { <td class="red">@(idx + 1)</td> <td class="red">@week</td> PublicHoliday = true; } } if (PublicHoliday == false) { if (week == "土") { <td class="blue">@(idx + 1)</td> <td class="blue">@week</td> } else if (week == "日") { <td class="red">@(idx + 1)</td> <td class="red">@week</td> } else { <td class="black">@(idx + 1)</td> <td class="black">@week</td> } } } @{ //状態フラグが"入力中"の場合、エディタの編集を許可する if (Model.MonthlyData.flag == "入力中") { <td> @Html.EditorFor(model => model.Kintais[idx].Open, new { htmlAttributes = new { @class = "form-control", style = "text-align:center" } }) @Html.ValidationMessageFor(model => model.Kintais[idx].Open, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.Kintais[idx].Close, new { htmlAttributes = new { @class = "form-control", style = "text-align:center" } }) @Html.ValidationMessageFor(model => model.Kintais[idx].Close, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.Kintais[idx].Rest, new { htmlAttributes = new { @class = "form-control", style = "text-align:center" } }) @Html.ValidationMessageFor(model => model.Kintais[idx].Rest, "", new { @class = "text-danger" }) </td> <td style="vertical-align:middle;text-align:center"> @Html.DisplayFor(model => model.Kintais[idx].Worktime) @Html.HiddenFor(model => model.Kintais[idx].Worktime) </td> <td style="vertical-align:middle;text-align:center"> @Html.DisplayFor(model => model.Kintais[idx].Overtime) @Html.HiddenFor(model => model.Kintais[idx].Overtime) </td> <td style="vertical-align:middle"> @Html.DropDownListFor(model => model.Kintais[idx].Situation, dictionary[Model.Kintais[idx].Situation], new { @class = "form-control", style = "width:130px;padding:5px" }) </td> <td style="width: 66px"> <nobr> <button type="button" onclick="setRegularWorkTime('@Html.IdFor(model => model.Kintais[idx].Open)', '@Html.IdFor(model => model.Kintais[idx].Close)', '@Html.IdFor(model => model.Kintais[idx].Rest)')" class="btn btn-primary"> 定時 </button> </nobr> </td> <td> @Html.EditorFor(model => model.Kintais[idx].Remark, new { htmlAttributes = new { @class = "form-control", style = "width:190px" } }) @Html.ValidationMessageFor(model => model.Kintais[idx].Remark, "", new { @class = "text-danger" }) </td> } //状態フラグが"入力中"以外の場合、エディタの編集を許可しない else { ・・・ } } ・・・ </tr> } ・・・ </table> </body> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") <script type="text/javascript"> //<![CDATA[ function setRegularWorkTime(from, to, rest) { document.getElementById(from).value = "@Model.PersonalInfo.ordinary_open"; document.getElementById(to).value = "@Model.PersonalInfo.ordinary_close"; document.getElementById(rest).value = "@Model.Rest_time"; } function setRegularMeetingTime(from, to) { document.getElementById(from).value = "18:30"; document.getElementById(to).value = "20:30"; } //]]> </script> }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/26 08:38
2018/12/27 02:26 編集
退会済みユーザー
2018/12/27 03:41
2018/12/27 04:03