2009幎10æ以éãããã€ãã®ASP.NET MVCãããžã§ã¯ãã§ããŒã ãšååããŠããŸãããããã»ã©æéã¯ããããããŸã å°é家ã§ã¯ãããŸããããã³ãŒããå°ãæ¹åããããã«éçºããããã€ãã®ã«ãŒã«ã«ã€ããŠèª¬æããããšæããŸãã ASP.NET MVCã¯ãä»ã®æ°ãããã¯ãããžãšåæ§ãæ£åžžã«äœ¿çšã§ããªãå ŽåããããŸããã倱æããäŸããããããã¿ã¹ã¯ãå®è£
ããããã®æé©ãªãªãã·ã§ã³ãéžæããããšã§ã³ãŒãã®æ¹åãåžžã«è©Šã¿ãŠããŸãã
ãŸãããã¥ãŒã®ã¿ã¹ã¯ã«ã€ããŠèããŠã¿ãŸãããããã®äž»ãªæ©èœã¯ããŒã¿ãHTMLã«æ¿å
¥ããããšã§ãã ãã®ã«ãŒã«ã¯ççŸãæé€ããŸã-ããŒã¿ãåä¿¡ãããããŒã¿ãéä¿¡ãããåã«HTMLã«ããŒã¿ãåã蟌ã¿ãŸãã ãããŠççŽã«èšã£ãŠãããã¯éåžžã«è€éã§ãã ç§ãåžžã«å®ãããšããŠããã¢ãããŒãã¯ãçµæã®HTMLã«å¯èœãªéãé¡äŒŒããããŒãžã¬ã€ã¢ãŠãïŒaspxïŒãäœæããããšã§ãã ãã®ã¢ãããŒãã®äž»ãªçç±ã¯ãå
ã®ããŒã¯ã¢ãããçµæã®ããŒã¯ã¢ããã«è¿ã¥ããŠãäºéã®äœæ¥ãæé€ããããšã§ãã å
ã®ããŒã¯ã¢ããã«ãdivãã衚瀺ãããdivããçµæã®HTMLã«å«ãŸããããšã確èªããŸãã
1.ãã¥ãŒã§å¯èœãªéãå°ãªãã³ãŒãã䜿çšãã
ãã®ã«ãŒã«ãæåã©ããã«åãåããªãã§ãã ãããã³ãŒãã¯ãŸã ãã¥ãŒã«ããã¯ãã§ãã ããšãã°ãããŒãã«ãäœæããåçŽãªãforãã«ãŒãããŸãã¯ç®¡çè
ã®æ©èœã衚瀺ãããifãã§ãããæ¥ä»åœ¢åŒã®æå»ãæååã®è§£æã決å®ããå¿
èŠã¯ãããŸãã-ããã¯ã¢ãã«ããã¥ãŒã«å¯ŸããŠè¡ãã¹ãããšã§ãã ããããã®èšç®ãè¡ããŸã-HTMLããå€ãã®CïŒã³ãŒãã衚瀺ãããå Žåãäœãééã£ãããšãããŸããã
Javascriptã«ããã®ã«ãŒã«ãé©çšããŸãã Javascriptããã¥ãŒã«è¡šç€ºãããªãçç±ãç§ã¯ããèšã£ãŠããŸããããããã£ãŠãããã¯ããªãã«ãšã£ãŠã·ã§ãã¯ã§ã¯ãªãã¯ãã§ãã JavaSciptãåå¥ã®ãã¡ã€ã«ã«ä¿åããŸãã
2.åä»ããã¥ãŒã䜿çšãã
ããã¯ãã³ã³ãããŒã©ãŒãããã¥ãŒã«ããŒã¿ãæž¡ãå¿
èŠããããã¹ãŠã®ãã¥ãŒã«åœãŠã¯ãŸããŸãã ãã¥ãŒã®ãã¥ãŒã¢ãã«ãäœæããã¢ãã«ãä»ããŠããŒã¿ã転éããŸãã ããã«ãããåæå®ãããHtmlHelperãªã©ãããŸããŸãªå¯èœæ§ãéãããŸãã çµæãšããŠããã¥ãŒéãŸãã¯ã³ã³ãããŒã©ãŒã¢ã¯ã·ã§ã³éã§ãã¥ãŒã¢ãã«ã䜿çšããå Žåãéåžžã«ãŸãã«ããçºçããŸããã GETãPOSTãããã³DELETEã®åå¥ã®ã¢ãã«ãäœæããŸãã ããå€ãã®éœæ°ã
3.ç¹å®ã®ãã¥ãŒã¿ã¹ã¯ã®ãã¥ãŒã¢ãã«ãäœæãã
ã¯ããããã¯äžèŠãããšãã¥ãŒãå®è£
ããæè¯ã®æ¹æ³ã§ã¯ãããŸããã ãã¥ãŒã¢ãã«ãäžè¬åãããããšãæçµçã«ãããŒã¿ã転éããããã«ãã¥ãŒã«å€ãã®ããžãã¯ãå®è£
ããå¿
èŠããããŸãã éèŠãªç¹ã¯ãã¢ãã«å
ã®ããŒã¿ãè¡šãã®ã«åœ¹ç«ã€ãããããŒã¿ãã¢ãã«ã«è»¢éãããšãã«ãæ£ãã圢åŒã§ããŒã¿ãååŸãããã¹ãŠã®äœæ¥ãè¡ãå¿
èŠãããããšã§ãã ã¢ãã«ãhtml CSSèŠçŽ ã®ã¯ã©ã¹ãå®çŸ©ããå¿
èŠãããå Žåã¯ç¹ã«ããããåžžã«äœ¿çšãç¶ããŸãã ãã¥ãŒã§ã¯ãããŒã¿ããŒã¹ããã®ããŒã¿ãããã¯ããã«å€ãã®ããšããããŸãã
泚ïŒViewã¢ãã«ã®äœ¿çšãäžè¬çã«ãªããViewã®ããŒã¿ãã·ã£ãŒãã«ãªããšãAutoMapperã¯éåžžã«äžè¬çã«ãªããŸãã
4.ç¬èªã®HTMLãã«ããŒã¯çŽ æŽããããã®ã§ã
ç¬èªã®Html Helper-ditchãäœæããã®ã¯éåžžã«ç°¡åã§ãããã®æ¹æ³ãåŠç¿ãããšããã«ãããããçŸããããšãç解ã§ããŸãã ããã¯ãããã€ãã®ããžãã¯ãã«ãã»ã«åãããã¥ãŒããåé€ããç°¡åãªæ¹æ³ã§ãã ãããã䜿çšããŠããããžã§ã¯ãã®ããŸããŸãªéšåã§äœ¿çšããã³ãŒããã«ãã»ã«åããŸãã
ç§ãæã
䜿çšããå¥ã®å°ããªããªãã¯ã¯ãHtml Helperå°çšã®ã¢ãã«ãäœæããããšã§ãã ãããžã§ã¯ãã«ã¯ã䜿çšãããã©ãŠã¶ãŒã«å¿ããŠã¬ã€ã¢ãŠããå€æŽããå¿
èŠãããå Žæãããã€ããããŸãããã®ããã«ããã©ãŠã¶ãŒãå®çŸ©ããHtmlãã«ããŒãäœæããŸãã
5.æšæºHTMLãã«ããŒ-çŽ æŽãããã§ãããHTMLãå¿ããªãã§ãã ãã
ãã®ã«ãŒã«ã®æå³ã¯ãããŒã¯ã¢ããæšæºHTMLãã«ããŒãçæãããã®ãç解ããããšã§ãã HTMLãã«ããŒã®æçšæ§ã«ãããããããããã€ãã®æ¬ ç¹ããããŸãïŒå±æ§ãååããŸãã¯ãå€ãã®å€æŽã¯éåžžã«äžå¿«ã§ãïŒã ããäºæž¬å¯èœãªçµæãââåŸãããã«ãæšæºHTMLïŒç¹ã«å
¥åïŒã«çœ®ãæããã»ããã¯ããã«ç°¡åãªå ŽåããããŸãã ããŒãã¹ãšããŠãããã«ãããæ°ããåŸæ¥å¡ãã³ãŒããç解ãããããªããŸãã çŸæç¹ã§ã¯ã50/50 HTMLãã«ããŒãšHTMLã䜿çšããŠããŸãã
æšæºã®HTMLèŠçŽ ãŸãã¯HTML HelperèŠçŽ ã䜿çšããã®ã¯éåžžã«é¢åã§ãã åãã³ãŒããäœåºŠãå
¥åããå¿
èŠããããŸãã Zen-Codingã«æ³šæããããšããå§ãããŸãã é©åãªãã©ã°ã€ã³ãã€ã³ã¹ããŒã«ããããšã§ãReSharperãã³ãã¬ãŒããŸãã¯Visual Studioã¹ããããã§ãåãããšãã§ããŸãã ããã«ãVisual Studioãã«ã¹ã¿ãã€ãºããæè¡ã¯ãåŠã¶å¿
èŠããããã®ã§ãã
6.ãã¹ãŠã®ãªã³ã¯ãUrl.ContentãŸãã¯Url.Actionã§ã©ããããŸã
ããŒãžãããã²ãŒãããããWebãµãŒãã¹ãåŒã³åºããããJavaScriptãšCSSãžã®ãªã³ã¯ãäœæãããããWebã¢ããªã±ãŒã·ã§ã³ããããŸãã å
žåçãªãããžã§ã¯ãã ãããã®ãªã³ã¯ã¯ãã¹ãŠUrl.ContentãŸãã¯Url.Actionãã«ããŒã§ã©ããããå¿
èŠããããŸãã ããã«ãããã¢ããªã±ãŒã·ã§ã³ããã¹ããŸãã¯ãããã€ããéã®å€ãã®äžè¬çãªåé¡ã解決ãããŸãã ããšãã°ãlocalhostïŒ898989 /ã§ã¢ããªã±ãŒã·ã§ã³ããã¹ãããŠãããmyserver / myapp /ã«ãããã€ããå¿
èŠããããŸããããªã³ã¯ã®å€§éšåã¯æ©èœããªããªããŸãã Url.ContentãšUrl.Actionã䜿çšããããšã§ãã®åé¡ã解決ã§ãããããåžžã«äœ¿çšããŠããŸãã
7. Ajaxãªã¯ãšã¹ããšçµã¿åãããŠéšåãã¥ãŒãæ¡çšãã
éšåãã¥ãŒã¯ããã¹ã¿ãŒããŒãžãšhtmlããã³bodyã¿ã°ãæããªããã¥ãŒã§ãã ãããã¯ããµãŒããŒäžã®ä»ã®è¡šçŸãšã¯ã©ã€ã¢ã³ãäžã®Javascriptã®äž¡æ¹ã§äœ¿çšã§ããŸãã JQueryã«ã¯ãæå®ãããURLãžã®èŠæ±ãå®è¡ããçµæã®HTMLããŒã¯ã¢ãããããŒãžã«æ¿å
¥ããåªãã$ .loadã¡ãœããããããŸãã ããã¯å€ãã®å Žåã«éåžžã«äŸ¿å©ã§ãã
ã¡ãã£ãšããããªãã¯ã䜿ãããšããããŸã-é·æéããŒã·ã£ã«ãã¥ãŒã«ããŒããããããŒã¯ã¢ããã®ãã©ã°ã¡ã³ããã©ããããŸãã 次ã«ãããŒãžãèªã¿èŸŒãŸããåŸãããŒã·ã£ã«ãã¥ãŒããããŒã¿ãååŸããŸãïŒJavascriptã®setTimeouté¢æ°ã䜿çšããŠ$ .loadãåŒã³åºããŸãïŒã ãããã£ãŠãå¿
èŠãªãã¹ãŠã®ããŒã¿ãä¿æããªããããã°ããããŒããããããŒãžãååŸããŸãã
8.ãã¹ã¿ãŒããŒãžãæ©èœããã
ããã¯ãAsp.net MVCãããžã§ã¯ãã®äœææã«æäŸããããã¹ã¿ãŒããŒãžã«æåã«åé¡ãããããšãæå³ãããã®ã§ã¯ãããŸããã 察ç
§çã«ã80ïŒ
ã®ã±ãŒã¹ã§ã¯ãããããŸãã«å¿
èŠãªãã®ã§ãã ããããã¡ã€ã³ããŒãžãäœããã¹ãããèŠã€ãããããã«ããã¹ã¿ãŒããŒãžããäžèŠãªãã®ããã¹ãŠåé€ããŸãã ãŸãããã¹ã¿ãŒããŒãžã®ç¶æ¿ã«ã€ããŠãå¿ããªãã§ãã ããã
9.ãã¶ã€ããŒã«äœãå¿
èŠãèããŠãã ããã
圌ãããã§ãªããŠãã ããã¯ç§ãåºå·ããäž»ãªãã¿ãŒã³ã§ãã çŽç²ãªhtmlãšcssã䜿çšãããã¶ã€ããŒãç§ã®ãµã€ããããé
åçã«ããããšãã§ãããšæããŸãã ã€ãŸããå¯èœãªéãçŽç²ãªhtmlã䜿çšãããã¿ã³ããªã³ã¯ã§ãæ©èœããããã«JavaScriptãã¿ã³ãã³ãã©ãŒãäœæããŸãïŒæšå¥šïŒåžžã«falseãè¿ããŸããããã«å¯ŸããjQueryãã©ã°ã€ã³ã¯ãŸã äœæããŠããŸããïŒ ã
10. CssãšJavaScriptã®ããŒãžã§ã³ç®¡ç
ããã¯å®éã«æ¬¡ã®æçš¿ã®ãããã¯ã§ãããããã«ãããããããcssãšJavascriptã®ããŒãžã§ã³ç®¡çã®ãããã¯ã«ã€ããŠç°¡åã«è§ŠããŸãã å®éãããã¯MVCã®ç¹ç°æ§ã§ã¯ãªãããã¹ãŠã®Webãããžã§ã¯ãã§äœ¿çšããå¿
èŠããããŸãã ç®æšã¯ããã©ãŠã¶ãŒã®ãã£ãã·ã¥ã«é¢ããåé¡ã解決ããããšã§ãã ããªãã¯ãããªãã®å©ããæ±ãã人ã«æåã«å°ããã®ã¯ã圌ããã©ãŠã¶ã®ãã£ãã·ã¥ãã¯ãªã¢ãããã©ããã ãšããããšãç¥ã£ãŠããŸãã ç§ã®æèŠã§ã¯ãã¢ã»ã³ããªããŒãžã§ã³ã®èªåæŽæ°ãã€ã³ã¹ããŒã«ããåJavascriptãã¡ã€ã«ã®æåŸã«ããŒãžã§ã³çªå·ãæ·»ä»ãã䟡å€ããããŸãã ãmyapp / ... / file.cssïŒããŒãžã§ã³= 1.0.0.256ãã®ããã«ãªããŸãã ãŸããã¿ã€ã ã¹ã¿ã³ãã®è¿œå ãåæ§ã®æ¹æ³ã§äœ¿çšããŸãã
å人ã®ãªã¯ãšã¹ãã§å
¬éãããŸãã æ®å¿µãªãããç§ã¯èªåã§æåŸ
ç¶ãæããããšãã§ããŸãããã ããã誰ã§ã圌ãã¡ãŒã«dimaumen [at] ukr [dot] netã«æåŸ
ã§ããŸãã