Hier versuche ich, einen neuen Kommentar auf den Klick der Schaltfläche ID = "abc" hinzuzufügen. Beim Klicken auf die Schaltfläche muss ein Ajax aufgerufen werden, von dem die Create-Aktion von TaskAssignedDailyLogController aufgerufen wird. Mit anderen Worten Ajax nicht schaffen getroffen hat Wirkung von TaskAssignedDailyLogsController
Nun, das Problem ist, dass Ajax die Aktion nicht nennen schaffen
unten AjaxAjax traf den Controller nicht
<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>
Unten ist 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>
}
Im Folgenden finden Sie Regler
[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);
}
Haben Sie versucht, Ihr Projekt nach Änderungen neu zu erstellen? –
Wie sind deine Routen definiert? – Tushar
Als erstes sollten Sie Ihren Konsolen- und Netzwerk-Tab auf Ajax-Fehler prüfen und die Ergebnisse hier melden. Das gibt uns einen Ausgangspunkt, von dem aus wir arbeiten können. Sie haben keinen Hinweis auf die Art des Problems gegeben außer "funktioniert nicht" – ADyson