{"action":"created","issue":{"url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/146","repository_url":"https://api.github.com/repos/MRCollective/ChameleonForms","labels_url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/146/labels{/name}","comments_url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/146/comments","events_url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/146/events","html_url":"https://github.com/MRCollective/ChameleonForms/issues/146","id":175016459,"number":146,"title":"Place for asking questions","user":{"login":"net4u","id":255743,"avatar_url":"https://avatars.githubusercontent.com/u/255743?v=3","gravatar_id":"","url":"https://api.github.com/users/net4u","html_url":"https://github.com/net4u","followers_url":"https://api.github.com/users/net4u/followers","following_url":"https://api.github.com/users/net4u/following{/other_user}","gists_url":"https://api.github.com/users/net4u/gists{/gist_id}","starred_url":"https://api.github.com/users/net4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/net4u/subscriptions","organizations_url":"https://api.github.com/users/net4u/orgs","repos_url":"https://api.github.com/users/net4u/repos","events_url":"https://api.github.com/users/net4u/events{/privacy}","received_events_url":"https://api.github.com/users/net4u/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-05T08:05:59Z","updated_at":"2016-09-07T14:29:27Z","closed_at":null,"body":"Hi,\r\n\r\nWhere is the best place for asking questions about usage for not perturbing this place with irelevant questions that are not bugs?\r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/comments/245298473","html_url":"https://github.com/MRCollective/ChameleonForms/issues/146#issuecomment-245298473","issue_url":"https://api.github.com/repos/MRCollective/ChameleonForms/issues/146","id":245298473,"user":{"login":"net4u","id":255743,"avatar_url":"https://avatars.githubusercontent.com/u/255743?v=3","gravatar_id":"","url":"https://api.github.com/users/net4u","html_url":"https://github.com/net4u","followers_url":"https://api.github.com/users/net4u/followers","following_url":"https://api.github.com/users/net4u/following{/other_user}","gists_url":"https://api.github.com/users/net4u/gists{/gist_id}","starred_url":"https://api.github.com/users/net4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/net4u/subscriptions","organizations_url":"https://api.github.com/users/net4u/orgs","repos_url":"https://api.github.com/users/net4u/repos","events_url":"https://api.github.com/users/net4u/events{/privacy}","received_events_url":"https://api.github.com/users/net4u/received_events","type":"User","site_admin":false},"created_at":"2016-09-07T14:29:27Z","updated_at":"2016-09-07T14:29:27Z","body":"OK, now I can provide a sample of what I have:\r\nFirst, code in controller (the concept is about using parameter for retrieving some data from a web service and send it back to the form for usage before form save)\r\n`        public ActionResult GetCompanyInfo(string CompanyNumber)\r\n        {\r\n            //call for openapi.ro //for hardcoded test may use e.g. 12345678 as Company dummy ID Code instead of CompanyNumber parameter; it will return 404 error\r\n            string CompanyCUI = CompanyNumber;\r\n            // Create a new 'Uri' object with the specified string.\r\n            Uri myUri = new Uri(\"https://api.openapi.ro/api/companies/\" + CompanyCUI + \".json\");\r\n            // Create a new request to the above mentioned URL. \r\n            WebRequest myWebRequest = WebRequest.Create(myUri);\r\n            //Add the required header to request (this is my particular case, as required by api provider\r\n            myWebRequest.Headers.Add(\"x-api-key\", \"a_personal_key_for_my_api_account\");\r\n            // Assign the response object of 'WebRequest' to a 'WebResponse' variable.\r\n            WebResponse myWebResponse = myWebRequest.GetResponse();\r\n            // Read the response into a stream\r\n            var dataStream = myWebResponse.GetResponseStream();\r\n            var reader = new StreamReader(dataStream);\r\n            var jsonResultString = reader.ReadToEnd();\r\n            // Deserialize\r\n            var CompanyInfoData = Newtonsoft.Json.JsonConvert.DeserializeObject<CustomersJSON>(jsonResultString);\r\n\r\n\r\n            return Json(CompanyInfoData,JsonRequestBehavior.AllowGet);\r\n        }`\r\n\r\nthe model where to deserialize is according to expected structure of JSON e.g.\r\n\r\n`        [DisplayName(\"Ultima prelucrare\")]\r\n        public string ultima_prelucrare { get; set; }\r\n        public string ultima_declaratie { get; set; }\r\n        public List<object> tva_la_incasare { get; set; }\r\n        public string tva { get; set; }\r\n        [DisplayName(\"Telefon:\")]\r\n        public string telefon { get; set; }\r\n        public string stare { get; set; }\r\n        public bool radiata { get; set; }\r\n        [DisplayName(\"Numar RC:\")]\r\n        public string numar_reg_com { get; set; }\r\n        public string judet { get; set; }\r\n        public string impozit_profit { get; set; }\r\n        public string impozit_micro { get; set; }\r\n        public string fax { get; set; }\r\n        [DisplayName(\"Numele companiei:\")]\r\n        public string denumire { get; set; }\r\n        public string cod_postal { get; set; }\r\n        [DisplayName(\"Cod Unic de Inregistrare\")]\r\n        public string cif { get; set; }\r\n        public string adresa { get; set; }\r\n        public string act_autorizare { get; set; }\r\n        public string accize { get; set; }`\r\n\r\nand now the view\r\n\r\n`@using ChameleonForms\r\n@using ChameleonForms.Component\r\n@using ChameleonForms.Enums\r\n@using ChameleonForms.Templates\r\n@using ChameleonForms.Templates.TwitterBootstrap3\r\n@using ChameleonForms.ModelBinders\r\n\r\n@model DirectInvoice.Models.Customers\r\n\r\n@{\r\n    ViewBag.Title = \"Create\";\r\n}\r\n\r\n<h2>Create Customer</h2>\r\n<p>Use for test e.g. 12345678 (dummy Company Code)</p>\r\n<br />\r\n\r\n<div>\r\n    @using (var f = Html.BeginChameleonForm())\r\n    {\r\n        @Html.AntiForgeryToken()\r\n        using (var s = f.BeginSection(\"Add a new customer\"))\r\n        {\r\n            @s.FieldFor(m => m.CompanyNumber)\r\n            <button id=\"Ask\" type=\"button\" class=\"btn btn-default\">Ask the web!</button>\r\n            @s.FieldFor(m => m.Name)\r\n            @s.FieldFor(m => m.CompanyRegistration)\r\n            @s.FieldFor(m => m.Phone1).Placeholder(\"0XX X XXX XXX\")\r\n            @s.FieldFor(m => m.Fax).Placeholder(\"0XX X XXX XXX\")\r\n            @s.FieldFor(m => m.Email).Placeholder(\"name@email.com\")\r\n            @s.FieldFor(m => m.Address)\r\n            @s.FieldFor(m => m.ZIP)\r\n            @s.FieldFor(m => m.City)\r\n        }\r\n        using (var n = f.BeginNavigation())\r\n        {\r\n            @n.Submit(\"Save customer...\").WithStyle(EmphasisStyle.Primary)\r\n        }\r\n    }\r\n</div>\r\n\r\n<div>\r\n    <hr/>\r\n    @Html.ActionLink(\"Back to List\", \"Index\")\r\n</div>\r\n\r\n@section Scripts {\r\n\r\n    <script type=\"text/javascript\">\r\n        $('#Ask').click(function () {\r\n\r\n            var companynumber = $('#CompanyNumber').val();\r\n\r\n            $.ajax({\r\n                type: 'POST',\r\n                data: {\r\n                    CompanyNumber: companynumber\r\n                },\r\n                //url for the controller's action method\r\n                url: '/Customers/GetCompanyInfo/', \r\n                dataType: \"json\",\r\n\r\n                success: function (data) {\r\n                    //Here you would update the textboxes, the 'data' variable contains the html/text from the fill\r\n                    $('#CompanyNumber').val(data.cif);\r\n                    $('#CompanyRegistration').val(data.numar_reg_com);\r\n                    $('#Name').val(data.denumire);\r\n                    $('#Phone1').val(data.telefon);\r\n                    $('#Fax').val(data.fax);\r\n                    $('#Address').val(data.adresa);\r\n                    $('#ZIP').val(data.cod_postal);\r\n                },\r\n                error: function () {\r\n                    //Manage errors\r\n                }\r\n\r\n            });\r\n            //console.log();\r\n        }\r\n    )\r\n    </script>\r\n}\r\n`\r\nHope that it may be useful for someone."}}
{"actor":{"display_login":"net4u"}}