html - Error while Calling Wcf restful service in mvc3? -
following operationcontract in iservice1 :
[operationcontract] [webget(uritemplate = "/getstates",responseformat = webmessageformat.json)] list<string> getstates(); implementation of method getstates in service1 class : public list<string> getstates() { db_mvcentities db = new db_mvcentities(); // string temp = countryname.country; string temp = "india"; var countryid = (from n in db.tblcountries n.country == temp select new { n.cid }).single(); int ii = countryid.cid; // int ii = (objectquery<int32>)countryid; // object oo = countryid; //int countryid = convert.toint32(countryid); var stateresult = (from n in db.tblstates n.cid == countryid.cid select n.statename).tolist(); list<string> aaa = new list<string>(); foreach (object o in stateresult) { string t = o.tostring(); aaa.add(o.tostring()); } return aaa; }
in above method taking state list database using entity framework. when executing wcf service on browser working fine.means getting following output
output of above service follows:
["mh","ap"] code consuming in mvc3, register.csheml file: $(document).ready(function () { $("#country").change(function () { $.ajax({ url: 'http://localhost:1264/service1.svc/getstates', type: 'get', contenttype: 'application/json; charset=utf-8', success: function (data) { $('#state option').remove(); $.each(data, function (index, val) { var optiontag = $('<option></option>'); $(optiontag).text(val.tostring()); $('#state').append(optiontag); }); }, error: function () { alert("bye..countryes."); } }); }); });
i getting following output when change event occurs of country: control not going in success method.
on success binding state list state dropdown list.
but unable json data in mvc3.
bye..countryes. error? in advance.
Comments
Post a Comment