gpt4 book ai didi

javascript - 无法从 TempData 获取数据

转载 作者:行者123 更新时间:2023-11-30 05:40:57 25 4
gpt4 key购买 nike

我在 controller_methodTempData 中保存了一些值。但是当我在 view 中访问它时,我什么也得不到...

Controller 代码:

public ActionResult Read_Surah()
{
TempData["Verse_Count"] = obj1.Total_Ayahs; // int data
return Json(new { key = Records }, JsonRequestBehavior.AllowGet);
}

查看部分:

 $.ajax({
url: "../Gateway/Admin_Mgmt?Action_Code=" + 115 + "&S_ID=" + surah_id,
type: 'Post',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
data: '',
success: function (result)
{
var mera_obj = result.key;
contents = mera_obj;
mera_obj.size;
@{
string q = (string)TempData["Verse_Count"];
}
alert(@q);
return false;
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error : " + xhr.responseText); },
});

但它在警报中显示“未定义”...

最佳答案

不要使用 TempData 将值从 Controller 传递给 View 。

使用 ViewBag,因为 TempData 用于为您提供从 Controller 到 Controller 或从操作到操作的数据。

引用链接:

http://www.codeproject.com/Articles/476967/WhatplusisplusViewData-2cplusViewBagplusandplusTem

关于javascript - 无法从 TempData 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20883999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com