データベースに入力された選択された値を持つようにcreate関数を取得しようとしています。作成ボタンを押すと、エラーはスローされませんが、データは移入されません。私は周波数フィールドが問題を引き起こしているとは確信していますが、解決策が出てこないのは確かです。データベースにデータを保存しない関数を作成します。
「通知名」の選択に応じて、ユーザーが選択できる頻度には2種類あります。 1つの選択には、数値、時間枠(週、月など)、前/後選択の3つの個別のフィールドがあります。もう1つは、瞬間的なものを静的なテキストフィールドとして表現します。どちらのオプションを選択しても、頻度データはデータベース内の1つのセルに取り込まれ、必要に応じて配管を使用して分離されます。私はまだC#MVCにはかなり新しいので、どんな助けも大歓迎です。
コントローラ:周波数オプションの
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.notificationType1, "Notification Name", htmlAttributes: new { @class = "control-label col-md-2 helper-format" })
<div class="col-md-10" id="type_selection">
@Html.DropDownList("notificationType1", new List<SelectListItem> {
new SelectListItem { Text = "Make a Selection", Value="" },
new SelectListItem { Text = "Incomplete Documents", Value= "Incomplete Documents" },
new SelectListItem { Text = "All Documents Complete", Value = "All Documents Complete" },
new SelectListItem { Text = "Documents Requiring Action", Value = "Documents Requiring Action" }
}, new { @class = "helper-format", @id = "value_select", style = "font-family: 'Roboto', Sans Serif;" })
@Html.ValidationMessageFor(model => model.notificationType1, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group" id="frequency_group">
@Html.LabelFor(model => model.frequency, "Frequency", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-sm-3" id="frequency_group">
@Html.TextBoxFor(model => model.frequency, new { @class = "textbox-width", @placeholder = "42" })
@Html.DropDownList("frequency", new List<SelectListItem>
{
new SelectListItem { Text = "Day(s)", Value= "| Day"},
new SelectListItem { Text = "Week(s)", Value= "| Week"},
new SelectListItem { Text = "Month(s)", Value= "| Month"}
})
@Html.DropDownList("frequency", new List<SelectListItem>
{
new SelectListItem { Text = "Before", Value= "| Before"},
new SelectListItem { Text = "After", Value= "| After"}
})
</div>
<p class="col-sm-2" id="psdatetext">The Beginning</p>
</div>
<div class="form-group" id="freq_instant">
@Html.LabelFor(model => model.frequency, "Frequency", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="instant_text">
<p>Instantaneous</p></div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.recipientTypeId, "Notification For", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("recipientTypeId", new List<SelectListItem>
{
new SelectListItem { Text = "Me", Value= "Me"},
new SelectListItem { Text = "Account Manager", Value="Account Manager" },
new SelectListItem { Text = "Candidate", Value= "Candidate"},
new SelectListItem { Text = "Recruiter", Value="Recruiter" },
new SelectListItem { Text = "Manager", Value= "Manager"}
})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-1 col-md-10">
<div id="hovercreate">
<button type="submit" value="CREATE" class="btn btn-primary" id="createbtn">CREATE</button>
</div>
</div>
</div>
</div>
}
JS
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
$(document).ready(function() {
$('#frequency_group').hide()
$('#freq_instant').hide()
$('#value_select').change(function() {
var selection = $('#value_select').val();
$('#frequency_group').hide();
switch (selection) {
case 'Incomplete Documents':
$('#frequency_group').show();
break;
case 'All Documents Complete':
$('#frequency_group').show();
break;
}
});
$('#value_select').on('change', function() {
if (this.value == 'Documents Requiring Action') {
$("#freq_instant").show();
}
else {
$("#freq_instant").hide();
}
});
});
この使用してEntity Frameworkのコードファーストですか?もしそうなら、発行されているSQLをチェックするのはなぜですか? ctx.Database.Logにロガーを追加して、トレース出力に書き込んでください。 –
ブラウザのネットワークツールを使用してHTTPリクエストを監視します。フォームは適切なURLにPOSTされていますか? – mason
ブレークポイントを設定し、デバッグし、送信しているデータにエラーがあるかどうかを確認します。 – Dhanashree