0
ここでは、id = "abc"ボタンのクリックに新しいコメントを追加しようとしています。 On ButtonAjaxをクリックすると、TaskAssignedDailyLogControllerのCreateアクションが呼び出される必要があります。他のワードアヤックスで今すぐTaskAssignedDailyLogsController
のアクションを作成をヒットしませんでしたが、問題は、Ajaxを作成するアクション以下
を呼び出していないということであるAjaxのAjaxコントローラにヒットしなかった
<script>
$(document).ready(function() {
$(document).on('click', '#abc', function() {
debugger
var you = $("#myForm1").serialize();
var parameter = { taskAssignedDailyLog: you };
$.ajax({
url: '@Url.Action("Create", "TaskAssignedDailyLogs")',
type: "post",
dataType: "html",
data: parameter,
success: function (data) {
alert(data);
$(".newCommentList").empty();
$(".newCommentList").html(data);
}
});
});
});
</script>
がCreate.cshtml
です以下は
@using (Html.BeginForm("Create", "TaskAssignedDailyLogs", FormMethod.Post, new { @id = "myForm1" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal empcreate">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(x => x.TskAssId)
<div class="form-group">
@Html.LabelFor(model => model.Comments, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Comments, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Comments, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.WrkHrs, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.WrkHrs, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.WrkHrs, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PercentCompleted, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PercentCompleted, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PercentCompleted, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="button" value="Create" class="btn btn-default" id="abc"> Add</button>
</div>
</div>
</div>
}
コントローラです
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(TaskAssignedDailyLog taskAssignedDailyLog)
{
if (ModelState.IsValid)
{
taskAssignedDailyLog.PostedBy = 1;
taskAssignedDailyLog.PostedOn = DateTime.Now.Date;
db.TaskAssignedDailyLogs.Add(taskAssignedDailyLog);
db.SaveChanges();
return RedirectToAction("Index", new { ProjectId =1 , TskAssId = taskAssignedDailyLog.TskAssId });
}
return View(taskAssignedDailyLog);
}
変更後にプロジェクトを再構築しようとしましたか? –
あなたのルートはどのように定義されていますか? – Tushar
最初に行うべきことは、コンソールとネットワークタブでajaxエラーを確認し、ここで結果を報告することです。それは私達に働く出発点を与えるでしょう。あなたは問題の本質を「動作しません」以外のものを与えていない – ADyson