﻿
{"id":3258,"date":"2015-09-09T22:18:24","date_gmt":"2015-09-09T22:18:24","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=3258"},"modified":"2015-09-09T22:18:24","modified_gmt":"2015-09-09T22:18:24","slug":"asp-net-mvcde-ajax-ile-json-formatinda-veri-post-etme","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-mvcde-ajax-ile-json-formatinda-veri-post-etme\/","title":{"rendered":"Asp.NET MVC&#8217;de Ajax \u0130le JSON Format\u0131nda Veri Post Etme"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Asp.NET MVC mimarisinde Ajax i\u015flemleri ger\u00e7ekle\u015ftirirken sunucuya nesne tipinde veri g\u00f6nderme mecburiyeti hissedebiliriz.B\u00f6yle bir durumda varaca\u011f\u0131n\u0131z nokta genellikle JSON veri format\u0131d\u0131r.Bu yaz\u0131m\u0131zda, Asp.NET MVC&#8217;de Ajax ile JSON format\u0131nda veri nas\u0131l Post edilir? ve bu veriyi istedi\u011fimiz referans tipinde nas\u0131l elde edebiliriz? gibi sorular\u0131n cevaplar\u0131na de\u011finece\u011fiz.<\/p>\n<p>A\u015fa\u011f\u0131daki gibi bir \u00f6\u011frenciyi modelleyen Entity \u00f6rne\u011fimiz olsun.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class Ogrenci\r\n    {\r\n        public int OgrenciNumarasi { get; set; }\r\n        public string Adi { get; set; }\r\n        public string SoyAdi { get; set; }\r\n        public int Yasi { get; set; }\r\n        public string Memleketi { get; set; }\r\n    }\r\n<\/pre>\n<p>\u015eimdi bu \u00f6\u011frenci s\u0131n\u0131f\u0131na uygun bir JSON veri yap\u0131s\u0131 olu\u015fturup, Server&#8217;a g\u00f6nderelim ve bu veriyi &#8220;Ogrenci&#8221; tipinde elde edelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;submit&quot; value=&quot;\u00d6\u011frenciyi JSON format\u0131nda g\u00f6nder&quot; id=&quot;btnGonder&quot; \/&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n    $(document).ready(function () {\r\n        $(&quot;#btnGonder&quot;).click(function () {\r\n\r\n\/\/--------- JSON Verisini Bu Arada Olu\u015fturdum--------------------\r\n            var Ogrenci = {\r\n                OgrenciNumarasi: 11040355,\r\n                Adi: 'Gen\u00e7ay',\r\n                SoyAdi: 'Y\u0131ld\u0131z',\r\n                Yasi: 23,\r\n                Memleketi: 'Artvin'\r\n            }\r\n\/\/--------- JSON Verisini Bu Arada Olu\u015fturdum--------------------\r\n\r\n            $.ajax({\r\n                url: '@Url.Action(&quot;OgrenciBilgisi&quot;, &quot;Home&quot;)',\r\n                type: 'POST',\r\n                dataType: 'json',\r\n                data: Ogrenci,\r\n                success: function (data) {\r\n                    alert(data);\r\n                }\r\n            });\r\n        });\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>Controller katman\u0131m\u0131zda da ilgili Action&#8217;\u0131 olu\u015ftural\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        &#x5B;HttpPost]\r\n        public JsonResult OgrenciBilgisi(Ogrenci o)\r\n        {\r\n            return Json(&quot;\u00d6\u011freci ba\u015far\u0131yla POST edilmi\u015ftir.&quot;, JsonRequestBehavior.AllowGet);\r\n        }\r\n<\/pre>\n<p>Evet, \u015fimdi projemizi derleyip \u00e7al\u0131\u015ft\u0131ral\u0131m ve butona t\u0131klad\u0131\u011f\u0131m\u0131zda program ak\u0131\u015f\u0131n\u0131n Break &#8211; Point ile yakalanm\u0131\u015f ekran g\u00f6r\u00fcnt\u00fcs\u00fcne bakal\u0131m.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2015\/09\/Asp.NET-MVCde-Ajax-\u0130le-JSON-Format\u0131nda-Veri-Post-Etme.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2015\/09\/Asp.NET-MVCde-Ajax-\u0130le-JSON-Format\u0131nda-Veri-Post-Etme.png\" alt=\"Asp.NET MVC&#039;de Ajax \u0130le JSON Format\u0131nda Veri Post Etme\" width=\"582\" height=\"163\" class=\"aligncenter size-full wp-image-3259\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2015\/09\/Asp.NET-MVCde-Ajax-\u0130le-JSON-Format\u0131nda-Veri-Post-Etme.png 582w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2015\/09\/Asp.NET-MVCde-Ajax-\u0130le-JSON-Format\u0131nda-Veri-Post-Etme-300x84.png 300w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/a><\/p>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi post i\u015flemi neticesinde Ogrenci nesnemiz otomatik olarak doldurulup elde edilmektedir.Bu sonucu otomatik bir \u015fekilde almam\u0131z\u0131n sebebi, olu\u015fturulan JSON nesnesinin \u00f6zellikleri ile Ogrenci nesnesinin \u00f6zelliklerinin benzerlik g\u00f6stermesidir.E\u011fer ki, arada benzer olmayan farkl\u0131 nesneler mevcutsa, bu durumda benzerler doldurulacak, di\u011ferleri Ogrenci nesnesi olarak elde edilemeyecektir.<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Asp.NET MVC mimarisinde Ajax i\u015flemleri ger\u00e7ekle\u015ftirirken sunucuya nesne tipinde veri g\u00f6nderme mecburiyeti hissedebiliriz.B\u00f6yle bir durumda varaca\u011f\u0131n\u0131z nokta genellikle JSON veri format\u0131d\u0131r.Bu yaz\u0131m\u0131zda, Asp.NET MVC&#8217;de Ajax ile JSON format\u0131nda veri nas\u0131l Post edilir? ve bu&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,18,19,780],"tags":[744,746,530],"class_list":["post-3258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ajax","category-javascript","category-jquery","category-json","tag-ajax","tag-asp-net-mvc","tag-json"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/3258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=3258"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/3258\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=3258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=3258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=3258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}