I have list on View from the controller, this is initialize when page is load.
@{
List<SomeClass> list = (List<SomeClass>) TempData["onload"];
}
I assign TempData["onload"] list to kendo treeview and set action("onSelect") when any item selected from treeview. than i have one js function ("onSelect") that fire when i select item from the treeviewlist. code behind the function:
::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;
}
});
}
::Controller::
public JavaScriptResult itemSelection_Changed(string pid, string cid)
{
ViewBag.ppi = pid;
ViewBag.cci = cid;
return JavaScript( "sometext" );
}
- after the request the ViewBag.ppi and ViewBag.cci is null. why?
- and if there is no possibility from ViewBag than there is any other way to set value in controller and get in view as c# variable?