我从视图中将数据发布到控制器,有两个按钮和标签,显示单击鼠标右键时第一条记录的名称,我将当前data-id和boolean字段传递给控制器方法,该方法返回json结果集,但我在视图中显示为空白。请帮助我显示预期的结果,即记录名称增加
我尝试过jquery post,也尝试过ajax post,我得到的结果类似于[object] [object]
这是我的控制器代码
[HttpPost]
public JsonResult ChangeSubject(int subjectid, bool Isincrement)
{
try
{
var currentSubjectOrder = db.SingleOrDefault<Subject>(subjectid).SubjectOrder;
if (Isincrement == true)
{
if (currentSubjectOrder < 3)
{
currentSubjectOrder ++;
}
}
else
{
if (currentSubjectOrder > 1)
{
currentSubjectOrder --;
}
}
var rs = db.SingleOrDefault<Subject>(currentSubjectOrder );
return Json(rs, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
我在调试器模式下获得了预期的结果,但未反映在视图上
@{
var Subject= (Subject)ViewBag.Subject;
}
<label id="subjectname">@Subject.SubjectName</label>
<div class="btn-group">
<button class="btn btn-default DropShadow decrement" data-sid="@Subject.SubjectId"><i class="fas fa-arrow-left fa-inverse DropShadow"></i></button>
<button class="btn btn-default DropShadow increment" data-sid="@Subject.SubjectId"><i class="fas fa-arrow-right fa-inverse DropShadow"></i></button>
</div>
$('。increment')。click(function(){
$.post('@Url.Action("ChangeSubject", "Subject")', { subjectid: $(this).data('sid'), Isincrement: true }).done(function (result) {
$('#subjectname').html(result);
});
});
$('.decrement').click(function () {
$.post('@Url.Action("ChangeSubject", "Subject")', { subjectid: $(this).data('sid'), Isincrement: false }).done(function (result) {
$('#subjectname').html(result);;
});
});
我希望在视图中的标签位置上显示下一个主题名称,反之亦然