我有一个非常奇怪的问题。我的ajax .post电话没有被推,我不明白为什么。它在另一种视图中正常工作,但是这个没有用。我一直在努力解决这个问题,但我真的需要尽快完成这个演示。任何帮助都会很精彩!
@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函数只是为了检查脚本是否正在执行,它是什么。
答案 0 :(得分:0)
你的意思是什么不起作用?
您需要在网络浏览器中打开此页面,点击F12。&gt;打开开发人员工具,转到“网络”选项卡,仅筛选出XHR请求。然后单击buitton并找到正在发送的请求。如果请求出现任何问题,.Net框架将以HTML错误页面响应。只要实际存在请求的控制器,您将获得某种类型的响应
我个人更喜欢