c# - Returning specific values with Jquery-Ajax request -
i working on webform knockout.js. @ 1 point, value based on selected value in select
list. have next code within viewmodel:
self.discoveryforms = ko.observablearray([]); self.selectedtemplate = ko.observable(); self.selecteddiscoveryform = ko.observable(); //behaviors self.selectedtemplate.subscribe(function (newvalue) { console.log(newvalue.discoveryformid()); self.getdiscoveryforms(newvalue.discoveryformid()); }); self.getdiscoveryforms = function (discoveryformid) { console.log(discoveryformid); $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", data: "{id: '" + discoveryformid + "'}", url: ("default.aspx/getdiscoveryforms"), datatype: "json", success: function (response) { self.finddiscoveryforms(response), console.log(response)} }); } self.finddiscoveryforms = function (response) { ko.mapping.fromjs(response.d, null, viewmodel.discoveryforms); ko.applybindings(viewmodel); }
the c# gets info entity this:
[webmethod] public static list<discoveryform> getdiscoveryforms(){ list<discoveryform> discoveryforms = new list<discoveryform>(); using (intranetcontainer db = new intranetcontainer()) { discoveryforms = db.discoveryforms.select(x => new discoveryform() { id = x.id, name = x.name, welcome = x.welcome, welcomenote = x.welcomenote, welcomeback = x.welcomeback, welcomebacknote = x.welcomebacknote }).tolist(); } homecoming discoveryforms; } public class discoveryform { public long id { get; set; } public string name { get; set; } public string welcome { get; set; } public string welcomenote { get; set; } public string welcomeback { get; set; } public string welcomebacknote { get; set; } }
the problem while want ajax request homecoming discovery forms id
selected selectedtemplate
, presently returns of values array. thought data: "{id: '" + discoveryformid + "'}",
that. can explain me why , how prepare it? should doing on c# side? i'm new javascript, ajax, , knockout.js.
to right problem, query had like:
data: "{'id':"+discoveryformid + "}",
and c# method changed according reply below.
your service must like
public static list<discoveryform> getdiscoveryforms(int[] ids){
and parameter must used query.
right don't have narrow set.
c# ajax jquery data-binding knockout.js
No comments:
Post a Comment