﻿
{"id":942,"date":"2012-11-19T13:59:20","date_gmt":"2012-11-19T13:59:20","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=942"},"modified":"2012-11-19T14:02:43","modified_gmt":"2012-11-19T14:02:43","slug":"asp-net-mvc-calisma-mekanizmasi-1","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-mvc-calisma-mekanizmasi-1\/","title":{"rendered":"Asp.NET MVC \u00c7al\u0131\u015fma Mekanizmas\u0131 &#8211; 1"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Art\u0131k Asp.NET MVC \u00e7al\u0131\u015fma mekanizmas\u0131n\u0131 inceleme vakti geldi.Bir \u00f6nceki yaz\u0131m\u0131zda olu\u015fturdu\u011fumuz &#8220;OrnekCalisma&#8221; ad\u0131ndaki proje \u00fczerinden devam edece\u011fiz.<\/p>\n<p>Hat\u0131rlarsan\u0131z e\u011fer, View ile Controller aras\u0131nda bir ba\u011f oldu\u011fundan bahsetmi\u015ftik.<br \/>\nKonuya girmeden \u00f6nce a\u015fa\u011f\u0131daki g\u00f6r\u00fcnt\u00fcy\u00fc incelemenizi tavsiye ediyorum.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/MVCGiris41.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-943\" title=\"MVCGiris4\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/MVCGiris41.png\" alt=\"\" width=\"278\" height=\"385\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/MVCGiris41.png 278w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/MVCGiris41-216x300.png 216w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/a><\/p>\n<p>Yukar\u0131daki g\u00f6r\u00fcnt\u00fcy\u00fc incelerseniz e\u011fer, View ile Conroller aras\u0131ndaki ba\u011f\u0131 az \u00e7ok g\u00f6rm\u00fc\u015f olacaks\u0131n\u0131z.Dikkat ederseniz Controller katman\u0131nda &#8220;AcconuntController.cs&#8221; ve &#8220;HomeController.cs&#8221; ad\u0131nda iki dosya mevcut.View katman\u0131na bakarsan\u0131z e\u011fer, &#8220;Account&#8221; ve &#8220;Home&#8221; ad\u0131nda iki klas\u00f6r mevcuttur.<br \/>\nBuradaki mant\u0131k \u015fudur.Controller katman\u0131nda herhangi bir isimde Controller&#8217;\u0131m olabilir.MVC mant\u0131\u011f\u0131na g\u00f6re o isimde View katman\u0131nda da klas\u00f6r bulunmal\u0131d\u0131r.<\/p>\n<p>\u015eimdi burada dikatimizi \u00e7eken bir nokta var.Controller k\u0131sm\u0131ndaki dosya ad\u0131nda, View k\u0131sm\u0131nda klas\u00f6r bulunmal\u0131 diyoruz ama g\u00f6r\u00fcnt\u00fcdeki dosya isimleri farkl\u0131 gibi g\u00f6z\u00fck\u00fcyor.Biri &#8220;AccountController&#8221; ken, di\u011feri &#8220;Account&#8221;.Evet bende sormu\u015ftum, bu \u015farta g\u00f6re View katman\u0131ndaki klas\u00f6r\u00fcn ad\u0131da &#8220;AccountController&#8221; olmas\u0131 gerekmiyor mu? diye.Asl\u0131nda Controller katman\u0131ndaki dosyalar\u0131n ger\u00e7ek ad\u0131, adlar\u0131ndaki &#8220;Controller&#8221; ifadesi \u00e7\u0131kar\u0131larak s\u00f6ylenir.Yukar\u0131daki g\u00f6r\u00fcnt\u00fcde &#8220;AccountController.cs&#8221; Controllerinin ad\u0131, &#8220;Account&#8221; Controllerid\u0131r.<\/p>\n<p>Zaten Controller olu\u015ftururken verdi\u011fimiz ismin sonuna &#8220;Controller&#8221; ifadesini eklemek zorunday\u0131z.\u00d6rnek olarak, Controller katman\u0131na sa\u011f t\u0131klay\u0131p Add diyerek bir Controller eklersek projemize Visual Studio&#8217;nun Controller isminin yan\u0131na &#8220;Controller&#8221; ifadesini ekledi\u011fini g\u00f6rece\u011fiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/ControllerIsmi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-944\" title=\"ControllerIsmi\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/ControllerIsmi.png\" alt=\"\" width=\"484\" height=\"194\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/ControllerIsmi.png 484w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/ControllerIsmi-300x120.png 300w\" sizes=\"auto, (max-width: 484px) 100vw, 484px\" \/><\/a><br \/>\nYukar\u0131daki g\u00f6r\u00fcnt\u00fcde de g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi, Visual Studio Controller eklerken bile verilecek ismin alan\u0131n\u0131 se\u00e7erek, yan\u0131na Controller ifadesini eklemi\u015ftir.<\/p>\n<p>\u015eimdi HomeController.cs dosyam\u0131z\u0131 a\u00e7arsak e\u011fer, g\u00f6rece\u011fimiz kodlar a\u015fa\u011f\u0131daki gibi olacakt\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &#x5B;HandleError]\r\n    public class HomeController : Controller\r\n    {\r\n        public ActionResult Index()\r\n        {\r\n            ViewData&#x5B;&quot;Message&quot;] = &quot;Welcome to ASP.NET MVC!&quot;;\r\n\r\n            return View();\r\n        }\r\n        public ActionResult About()\r\n        {\r\n            return View();\r\n        }\r\n    }\r\n<\/pre>\n<p>View katman\u0131ndaki Home ismindeki klas\u00f6r\u00fcn i\u00e7ine g\u00f6z atal\u0131m.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/HomeKlasoru.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-945\" title=\"HomeKlasoru\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/HomeKlasoru.png\" alt=\"\" width=\"176\" height=\"56\" \/><br \/>\n<\/a><br \/>\nView katman\u0131 ile Controller katman\u0131 aras\u0131ndaki ba\u011f\u0131n gerek\u00e7elerinden biri, Controller&#8217;daki bulunan dosyan\u0131n ayn\u0131 isminde View katman\u0131nda klas\u00f6r\u00fc bulunmas\u0131 gerekti\u011fini s\u00f6ylemi\u015ftik.<\/p>\n<p>HomeController.cs ismindeki Controller&#8217;\u0131 a\u00e7t\u0131\u011f\u0131m\u0131z zaman i\u00e7indeki kodlar\u0131 yukar\u0131da g\u00f6rd\u00fck.Dikkat ederseniz,Controller s\u0131n\u0131f\u0131ndan kal\u0131t\u0131m alm\u0131\u015f, HomeController ad\u0131ndaki bir s\u0131n\u0131f g\u00f6r\u00fcyoruz.Bu s\u0131n\u0131f\u0131n i\u00e7inde iki tane ActionResult tipinden metod mevcut.Birinin ad\u0131 &#8220;Index&#8221; di\u011feri ise &#8220;About&#8221;.View katman\u0131 i\u00e7inde bulunan Home klas\u00f6r\u00fcn\u00fc incelersek e\u011fer, i\u00e7inde About.aspx ve Index.aspx dosyalar\u0131n\u0131n mevcut oldu\u011funu g\u00f6rece\u011fiz.\u0130\u015fte MVC de Controller ve View aras\u0131ndaki ili\u015fki bu \u015fekilde kurulmaktad\u0131r.<\/p>\n<p>View katman\u0131 i\u00e7inde Controller katman\u0131ndaki ayn\u0131 dosya ismine sahip klas\u00f6rler yap\u0131land\u0131r\u0131yoruz.Bu Controller dosyas\u0131n\u0131n i\u00e7indeki ActionResult tipinden olan metodlar\u0131n isimleride, View katman\u0131ndaki klas\u00f6r\u00fcn\u00fcn i\u00e7inde bulunan sayfa isimleri olmak zorundad\u0131r.<\/p>\n<p>\u015eimdi Index ve About metumuzun ba\u015f\u0131na birer Break Point koyuyorum ve program\u0131m\u0131z\u0131 \u00e7al\u0131\u015ft\u0131r\u0131yorum.E\u011fer ayn\u0131 \u015fekilde sizlerde Break Point yapt\u0131ysan\u0131z, g\u00f6receksiniz ki, Index metodunda Break Point tak\u0131lacakt\u0131r.<\/p>\n<p>Neden About metodumuzda de\u011filde, Index metodumuzda Break Point tak\u0131ld\u0131?Kod sayfas\u0131nda About metodumuzdan \u00fcst s\u0131rada olmas\u0131ndan dolay\u0131 olabilir mi?<\/p>\n<p>Tabikide hay\u0131r.Bu sorunun cevab\u0131 Global.asax dosyas\u0131nda sakl\u0131d\u0131r.Bu yaz\u0131m\u0131z\u0131n ilerisinde bu konuya tekrardan de\u011finece\u011fiz.<\/p>\n<p>Biz F11&#8217;e basarak Break Point&#8217;i devam ettirelim.Tabi devam ederken Index metodu i\u00e7inde a\u015fa\u011f\u0131daki kod blo\u011funuda okuyaca\u011f\u0131z.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nViewData&#x5B;&quot;Message&quot;] = &quot;Welcome to ASP.NET MVC!&quot;;\r\n<\/pre>\n<p><span style=\"color: #339966;\"><strong> ViewData[&#8220;De\u011fi\u015fkenIsmi&#8221;] Nedir?<\/strong><\/span><br \/>\nView katman\u0131 ile Controller katman\u0131 aras\u0131nda bir ba\u011f oldu\u011fundan dolay\u0131, kullan\u0131c\u0131 taraf\u0131ndan bir istek yap\u0131ld\u0131\u011f\u0131 zaman, ilk ba\u015fta Controller katman\u0131 \u00e7al\u0131\u015f\u0131yor daha sonra View katman\u0131nda o Controller&#8217;a ba\u011fl\u0131 olan sayfa \u00e7al\u0131\u015f\u0131yor.E\u011fer ben Controller&#8217;dan View katman\u0131na bir bilgi aktarmak istiyorsam, bu i\u015flemi ViewData[&#8220;De\u011fi\u015fkenIsmi&#8221;] eleman\u0131yla yapabiliyorum.<\/p>\n<p>Break Point&#8217;e kald\u0131\u011f\u0131m\u0131z yerden devam edersek e\u011fer, &#8220;return View();&#8221; kodlar\u0131n\u0131 i\u015fletece\u011fiz.Bu kodu irdelersek e\u011fer, View sayfama geri d\u00f6n\u00fc\u015f yapmas\u0131 gerekti\u011fini s\u00f6yl\u00fcyor.<\/p>\n<p>E\u011fer Break Point&#8217;le devam edersek, Index.aspx sayfas\u0131 a\u00e7\u0131lana kadar F11&#8217;e basal\u0131m.<\/p>\n<p>Neden Index.aspx sayfas\u0131 a\u00e7\u0131l\u0131yorda, About.aspx sayfas\u0131 a\u00e7\u0131lm\u0131yor.Bunun nedenini buraya kadar okuduysak art\u0131k biliyoruz.Controller&#8217;\u0131m\u0131z View&#8217;da ili\u015fkili oldu\u011fu klas\u00f6re gidiyor.ActionResult tipindeki Index isimli metodu \u00e7al\u0131\u015ft\u0131rd\u0131\u011f\u0131m\u0131z i\u00e7in, Index ad\u0131ndaki dosyay\u0131, o klas\u00f6rde ar\u0131yor ve getiriyor.<\/p>\n<p>E\u011fer, View katman\u0131 i\u00e7inde Home klas\u00f6r\u00fc alt\u0131nda Index.aspx dosyas\u0131 mevcut olmas\u0131n, sistem bulamad\u0131m diye hata verecektir.<\/p>\n<p>En sonunda Break Point&#8217;e devam edersek Index.aspx sayfas\u0131 a\u00e7\u0131lacakt\u0131r.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/anasayfa.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-947\" title=\"anasayfa\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/anasayfa.png\" alt=\"\" width=\"407\" height=\"52\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/anasayfa.png 407w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/anasayfa-300x38.png 300w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><\/a><br \/>\nYukar\u0131da g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi a\u00e7\u0131lan sayfan\u0131n sa\u011f \u00fcst k\u00f6\u015fesinde Home ve About linkleri mevcuttur.<br \/>\nE\u011fer bu linklerin \u00fczerine gelirsem, taray\u0131c\u0131n\u0131n sol alt k\u00f6\u015fesinde \u00e7\u0131kan linklere dikkat edelim.<\/p>\n<table style=\"width: 100%;\">\n<tbody>\n<tr>\n<td>Home linki \u00fczerinde<\/td>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/Home.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-948\" title=\"Home\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/Home.png\" alt=\"\" width=\"113\" height=\"18\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>About linki \u00fczerinde<\/td>\n<td><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/About.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-949\" title=\"About\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2012\/11\/About.png\" alt=\"\" width=\"186\" height=\"16\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">Burada dikkat etmenizi istedi\u011fim iki husus var.About linkine bakarsak e\u011fer, ..\/Home\/About\/ yap\u0131s\u0131ndad\u0131r.Bunu nas\u0131l bir benze\u015fim yapabiliriz.Controller dosyas\u0131 Home(Controller) olan, HomeController i\u00e7indeki ActionResult tipindeki metodunun ad\u0131da About olan diyebiliriz.Ya da View katman\u0131ndaki klas\u00f6r\u00fc Home olan, Home klas\u00f6r\u00fc i\u00e7indeki About.aspx dosyas\u0131 diyebiliriz.Di\u011fer bir husus ise, Home linkini g\u00f6zlemlersek, About linkindeki gibi bir yap\u0131 bulunmamaktad\u0131r.Yani burada Home linkini varsay\u0131lan bir link g\u00f6rd\u00fc\u011f\u00fcnden dolay\u0131 bu \u015fekilde bir link yap\u0131s\u0131na sahiptir.Bu yap\u0131n\u0131n s\u0131rr\u0131da Global.asax dosyas\u0131ndad\u0131r.\u0130leride bunada de\u011finece\u011fim.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>E\u011fer a\u00e7\u0131lan pencerede About linkine t\u0131klarsak, Index sayfas\u0131ndaki mant\u0131k gibi sistem ileyecektir.Yani Controller katman\u0131yla ileti\u015fim kurulacak.HomeController dosyas\u0131n\u0131n i\u00e7indeki About metodunu \u00e7al\u0131\u015ft\u0131racak ve View katman\u0131 i\u00e7indeki, Controller ile ayn\u0131 isimde olan Home klas\u00f6r\u00fcndeki About.aspx sayfas\u0131n\u0131 \u00e7a\u011f\u0131racakt\u0131r.<\/p>\n<p>Bu yaz\u0131m\u0131zda MVC&#8217;de View ve Controller katmanlar\u0131 aras\u0131ndaki mant\u0131\u011f\u0131 anlatmaya \u00e7al\u0131\u015ft\u0131m.Bir sonraki yaz\u0131mda MVC&#8217;de Global.asax dosyas\u0131n\u0131n \u00f6nemi, kullan\u0131m\u0131 ve bu sayfadaki baz\u0131 Global.asax dosyas\u0131yla alakal\u0131 me\u00e7hul bilgileri anlatan i\u00e7erikte olacakt\u0131r.<\/p>\n<p>Bir sonraki yaz\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere.<\/p>\n<p>\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>Art\u0131k Asp.NET MVC \u00e7al\u0131\u015fma mekanizmas\u0131n\u0131 inceleme vakti geldi.Bir \u00f6nceki yaz\u0131m\u0131zda olu\u015fturdu\u011fumuz &#8220;OrnekCalisma&#8221; ad\u0131ndaki proje \u00fczerinden devam edece\u011fiz. Hat\u0131rlarsan\u0131z e\u011fer, View ile Controller aras\u0131nda bir ba\u011f oldu\u011fundan bahsetmi\u015ftik. Konuya girmeden \u00f6nce a\u015fa\u011f\u0131daki g\u00f6r\u00fcnt\u00fcy\u00fc incelemenizi tavsiye&#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":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[746,286,283],"class_list":["post-942","post","type-post","status-publish","format-standard","hentry","category-asp-net-mvc","tag-asp-net-mvc","tag-global-asax","tag-mvc"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/942","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=942"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}