【发布时间】:2016-07-02 12:30:24
【问题描述】:
在我的 DNN MVC 开发过程中出现了另一个问题。我想知道这是否是我犯了错误的错误/缺失功能。 我将尝试在下面解释问题。
我想要达到的目标
我想通过调用 AJAX 帖子在我的控制器中执行一个操作。到目前为止它有效。 但是,当我尝试将一些变量返回到我的视图时,它不仅返回变量。它将整个 HTML 源添加到响应中。
我的控制器
我的方法返回一个 ActionResult(我尝试了 JsonResult 和不同的东西:HttpResponseMessage 以及)。 该程序本身正在运行并且确实返回 JSON 消息。
public ActionResult Mark(int itemId)
{
var item = _itemService.GetItem(itemId, ModuleContext.ModuleId);
// Check if item exists
if (item == null)
return Json(new { success = false, Description = "the item you want to vote for does not exist (anymore)" }, JsonRequestBehavior.AllowGet);
// Check if user is voting on his own item
if (item.CreatedByUserId == User.UserID)
return Json(new { success = false, Description = "it is not allowed to vote for your own item" }, JsonRequestBehavior.AllowGet);
我的观点
下面的视图不是我的最终视图,而是用来测试的。
$("#button").click(function () {
$.ajax({
type: "POST",
url: "@Url.Action("Mark", "Vote")",
dataType: "json",
data: { itemId: JSON.stringify(16) },
success: function (data) { console.log(data); },
error: function (errMsg) {
responseText = jQuery.parseJSON(errMsg.responseText);
console.log(responseText.Description);
}
});
});
这是一个错误,还是我能够修复的问题?非常感谢您的宝贵时间。 https://dnntracker.atlassian.net/browse/DNN-8522
【问题讨论】:
-
好像已经有类似问题的解决方案了。 dnntracker.atlassian.net/plugins/servlet/mobile#issue/DNN-7297
标签: jquery json asp.net-mvc dotnetnuke