У меня очень странная проблема. Мой вызов ajax .post не толкается, и я понятия не имею, почему. Он работает в другом представлении просто отлично, но этот не работает. Я изо всех сил пытаюсь понять это, но мне действительно нужно сделать это в ближайшее время для презентации. Любая помощь будет замечательной!Ajax вызов не толкается?
@model ProjectCrux.Models.QuestionLinkToHashtag
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<h2>Details</h2>
@{
var info = ViewBag.SortingPagingInfo;
}
@using(Html.BeginForm("Details", "Question", FormMethod.Post)){
@Html.Hidden("SortField", (string)info.SortField)
@Html.Hidden("SortDirection", (string)info.SortDirection)
@Html.Hidden("PageCount", (int)info.PageCount)
@Html.Hidden("PageSize", (int)info.PageSize)
@Html.Hidden("CurrentPageIndex", (int)info.CurrentPageIndex)
<div>
<h4>Question</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Question.Student.firstName)
</dt>
<dd>
@Html.DisplayFor(model => model.Question.Student.firstName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Question.question)
</dt>
<dd>
@Html.DisplayFor(model => model.Question.question)
</dd>
</dl>
</div>
<div id="Answers">
<table border="1" cellpadding="10">
@foreach (var item in ViewBag.answers)
{
<tr>
<td>@item.answer</td>
<td>@item.postDate</td>
</tr>
}
<tr>
<td colspan="4">
@for (var i = 0; i < info.PageCount; i++)
{
if (i == info.CurrentPageIndex)
{
<span>@(i + 1)</span>
}
else
{
<a href="#" data-pageindex="@i"
class="pager">@(i + 1)</a>
}
}
<script>
$(document).ready(function() {
$(".pager").click(function (evt) {
var pageindex = $(evt.target).data("pageindex");
$("#CurrentPageIndex").val(pageindex);
evt.preventDefault();
$("form").submit();
});
});
</script>
</td>
</tr>
</table>
<div class="posted">
@Html.EditorFor(model => model.Answers.answer, new { htmlAttributes = new { @class = "answerBox" } })
<button type="button" id="button">Post</button>
<script>
$("button").click(function() {
$(".posted").hide();
$.post("Create", $(".posted").serialize(), function (data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
$(".posted").show(1000)
});
</script>
</div>
</div>
<p>
<!--Html.ActionLink("Edit", "Edit", new { id = Model.questionId }) |-->
@Html.ActionLink("Back to List", "Index")
</p>
}
Функции show/hide, которые я реализовал, чтобы проверить, выполняется ли сценарий, каков он.