c# - create object of viewModel in view in asp.net mvc -
i've created object of class in controller in asp.net mvc , pass view page view model,
this object has many methods return different data type (xmldocument
, string
, int
, array
, etc)
i've used following way access methods @model.getxml().childnodes.count" "@model.getxml().childnodes[0].innertext
i want declare variable of object in javascript , call methods want variable following
var obj=@model
and access methods obj
variable
but have problem when write loop tracing elements in array following
var size=parseint("@model.getxml().childnodes.count"); (var i=0; i<size; i++) { document.writeln ("@model.getxml().childnodes[i].innertext"); }
this code didn't work, appreciated.
you mixing server-side code (c#) , client-side code (javascript)
you should convert values in json or xml , put in hidden field , process value in hidden field in loop in javascript aka client-side..
to identify server-side code
@model.getxml().childnodes.count
, @model.getxml.childnodes[i].innertext
server code cannot combined in particular case javascript code
to identify client-side code
var size=parseint(<variable>); (var i=0; i<=0; i++) { document.writeln ("<text>"); }
currently suppose printing many times count
@model.getxml.childnodes[i].innertext
@model.getxml.childnodes[i].innertext
Comments
Post a Comment