我有来自控制器的View列表,这是在页面加载时初始化。
@{
List<SomeClass> list = (List<SomeClass>) TempData["onload"];
}
当从树视图中选择任何项目时,我将TempData [&#34; onload&#34;]列表分配给剑道树视图并设置动作(&#34; onSelect&#34;)。 比我有一个js函数(&#34; onSelect&#34;),当我从treeviewlist中选择项目时触发。 函数背后的代码:
:: VIEW ::
function(e){
...code...
$.ajax({
type: "POST",
url: "/Report/itemSelection_Changed", // the URL of the controller action method
data: {pid : parentid, cid : currentnodeid}, // optional data
dataType: "json",
success: function (result) {
text = result;
var yoo = null;
document.getElementById("descriptionbox").value = text
if ('@ViewBag.ppi' != null && '@ViewBag.cci' != null) {
yoo = '@list[ (int) ViewBag.ppi].childrens[ (int) ViewBag.cci].extratxt';
}
//here i want to use yoo.
},
error: function (req, status, error) {
text = req.responseText;
document.getElementById("descriptionbox").value = text;
}
});
}
::控制器::
public JavaScriptResult itemSelection_Changed(string pid, string cid)
{
ViewBag.ppi = pid;
ViewBag.cci = cid;
return JavaScript( "sometext" );
}