Click here to Skip to main content
15,888,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
i cant access k inside objDllColl[k] in Additional Data function kendo?


k doesn't exist in the context

What I have tried:

function onAdditional() {
debugger
var k = 0;
var ParamArray = new Array();
@*var points = @Html.Raw(Json.Encode(@Model.objDllColl[1].Parameters))*@
var postObj = @Model.objDllColl[k].Parameters
ParamArray.push(postObj);
//ParamArray.push(points);
k++

return {
Parameters: JSON.stringify(ParamArray),
SPKey: "ElementsDetailsSelect",
ListInclusion: "All",
TextFieldIndex: 0,
ValueFieldIndex: 2
}
}
Posted
Updated 18-Mar-16 20:19pm
Comments

1 solution

you asked a question with same problem 2 days ago and got an explanation by F-ES Sitecore. Why do you think the answer is different today ?
Can't access j inside for loop in javascript. How to do?[^]
Writed by F-ES Sitecore:
The code after "@" is executed server-side before the resulting html is sent to the browser. "j" exists as a javascript variable when the html runs in the browser, so you can't use it in your server-side code as it doesn't exist in that context. You need to construct all of the js using server code, something like this

function onAdditional() {
    debugger;
    var ParamArray = new Array();
    var points;

    @foreach(var m in Model.objDllCollection)
    {
        string p = string.Format("points = {0};\r\nParamArray.push(points);\r\n", Json.Encode(m.Parameters));
        @Html.Raw(p);
    } 
}
 
Share this answer
 
v2
Comments
Sathish km 19-Mar-16 6:06am    
can u able put p in @Html.Raw(), for me the same problem exists. How ?
Sathish km 23-Mar-16 2:12am    
Thank u for ur reply...

return {
Parameters: JSON.stringify(ParamArray),
}
How do i return @Html.Raw(p); instead of JSON.stringify(ParamArray),
Patrice T 23-Mar-16 2:21am    
I don't know .
Your question is about another problem, you should first apply the correction of this problem.
Then ask again with corrected code and updated question about new problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900