こんにちわ!
https://teratail.com/questions/162436の続きになりますが、以前ボタンをクリックするとエディタに文字列を入力する処理を作成しました。
今回はボタンを押してTimeSpan型変数の値を入力したいのですが、いろいろ試しましたがうまくいかずに困っています。
以下に写真とソースコードを記載します。この処理自体はビューの中でのみ、sectionScriptsで行われています。現状ではボタンを押すと決まった時刻("9:00"等)を入力してますが、それをModel.PersonalInfo.ordinary_openを入力するようにしたいです。
よろしくお願いします。
モデル:
KintaiModel.cs namespace Kintai_CS_.Models { public class KintaiModel { public TPersonalInfo PersonalInfo { get; set; } } } TPersonalInfo.cs namespace Kintai_CS_.Models { using System; using System.Collections.Generic; public partial class TPersonalInfo { public string emp_num { get; set; } public string user_name { get; set; } public int remain_paidholiday { get; set; } public int remain_compensatoryholiday { get; set; } public System.TimeSpan ordinary_open { get; set; } public System.TimeSpan ordinary_close { get; set; } public System.TimeSpan rest_start { get; set; } public System.TimeSpan rest_end { get; set; } } }
コントローラ:
namespace Kintai_CS_.Controllers { public class TKintaisController : Controller { private mvcdbEntities db = new mvcdbEntities(); // GET: TKintais public ActionResult Index(LoginInfo loginInfo) { ・・・ //個人情報をモデルへ model.PersonalInfo = db.TPersonalInfo.Find(loginInfo.Emp_num); ・・・ //モデルをビューへ return View(model); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Index(KintaiModel model, string update, string lastMonth, string nextMonth, string logOut) { ・・・ } }
ビュー:
@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"> ・・・ </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 { ・・・ } } @Html.HiddenFor(model => model.Kintais[idx].Emp_num) @Html.HiddenFor(model => model.Kintais[idx].Date) @Html.HiddenFor(model => model.Kintais[idx].Id) </tr> } @Html.HiddenFor(model => model.MonthlyData.id) @Html.HiddenFor(model => model.MonthlyData.emp_num) </table> </body> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") <script type="text/javascript"> //<![CDATA[ function setRegularWorkTime(from, to, rest) { document.getElementById(from).value = "09:00"; document.getElementById(to).value = "18:00"; document.getElementById(rest).value = "01:00"; } function setRegularMeetingTime(from, to) { document.getElementById(from).value = "18:30"; document.getElementById(to).value = "20:30"; } //]]> </script> }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/26 04:02
退会済みユーザー
2018/12/26 04:07
2018/12/26 04:24