{"id":5275,"date":"2022-06-27T03:07:03","date_gmt":"2022-06-27T03:07:03","guid":{"rendered":"https:\/\/trithucmoi.net.vn\/?p=5275"},"modified":"2022-07-12T03:51:43","modified_gmt":"2022-07-12T03:51:43","slug":"xay-dung-web-ui-va-web-api-su-dung-asp-net-core-mvc","status":"publish","type":"post","link":"https:\/\/trithucmoi.net.vn\/index.php\/2022\/06\/27\/xay-dung-web-ui-va-web-api-su-dung-asp-net-core-mvc\/","title":{"rendered":"X\u00e2y d\u1ef1ng web UI v\u00e0 web API s\u1eed d\u1ee5ng ASP.NET Core MVC"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>C\u00f3 th\u1ec3 t\u1ea1o ra c\u00e1c \u1ee9ng d\u1ee5ng web c\u00f3 th\u1ec3 testing theo m\u00f4 h\u00ecnh MVC (Model-View-Controller)<\/li><li>C\u00f3 th\u1ec3 x\u00e2y d\u1ef1ng HTTP services c\u00e1i m\u00e0 h\u1ed7 tr\u1ee3 nhi\u1ec1u \u0111\u1ecbnh d\u1ea1ng v\u00e0 c\u00f3 \u0111\u1ea7y \u0111\u1ee7 h\u1ed7 tr\u1ee3 cho n\u1ed9i dung c\u1ee7a d\u1eef li\u1ec7u tr\u1ea3 v\u1ec1<\/li><li>Razor cung c\u1ea5p m\u1ed9t ng\u00f4n ng\u1eef hi\u1ec7u qu\u1ea3 \u0111\u1ec3 t\u1ea1o Views<\/li><li>Tag Helper cho ph\u00e9p code server side tham gia v\u00e0o vi\u1ec7c t\u1ea1o v\u00e0 render ph\u1ea7n t\u1eed HTML<\/li><li>Model Binding t\u1ef1 \u0111\u1ed9ng \u00e1nh x\u1ea1 d\u1eef li\u1ec7u t\u1eeb HTTP request t\u1edbi tham s\u1ed1 c\u1ee7a method action<\/li><li>Model Validation t\u1ef1 \u0111\u1ed9ng th\u1ef1c hi\u1ec7n validate client v\u00e0 server<\/li><\/ul>\n\n\n\n<p>\u1ee8ng d\u1ee5ng web v\u1edbi m\u00e3 HTML do server sinh ra l\u00e0 lo\u1ea1i \u1ee9ng d\u1ee5ng c\u01a1 b\u1ea3n v\u00e0 truy\u1ec1n th\u1ed1ng m\u00e0 ASP.NET Core h\u1ed7 tr\u1ee3. \u0110\u1ec3 ph\u00e1t tri\u1ec3n c\u00e1c lo\u1ea1i \u1ee9ng d\u1ee5ng n\u00e0y b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng m\u00f4 h\u00ecnh l\u1eadp tr\u00ecnh <strong>MVC<\/strong> ho\u1eb7c <strong>Razor Pages.<\/strong><\/p>\n\n\n\n<p><strong>ASP.NET Core MVC <\/strong>&nbsp;l\u00e0 m\u00f4 h\u00ecnh l\u1eadp tr\u00ecnh \u1ee9ng d\u1ee5ng web t\u01b0\u01a1ng t\u1ef1 nh\u01b0 ASP.NET MVC quen thu\u1ed9c. C\u00e1c th\u00e0nh ph\u1ea7n c\u1ee7a \u1ee9ng d\u1ee5ng \u0111\u01b0\u1ee3c ph\u00e2n chia ra c\u00e1c th\u00e0nh ph\u1ea7n tu\u00e2n theo m\u1eabu ki\u1ebfn tr\u00fac MVC (Model \u2013 View \u2013 Controller), t\u01b0\u01a1ng t\u1ef1 nh\u01b0 Ruby on Rails, Java Spring ho\u1eb7c Django.<\/p>\n\n\n\n<p><strong>Razor Pages <\/strong>l\u00e0 m\u00f4 h\u00ecnh \u0111\u01a1n gi\u1ea3n h\u00f3a c\u1ee7a MVC, ch\u1ec9 bao g\u1ed3m th\u00e0nh ph\u1ea7n V (View) vi\u1ebft b\u1eb1ng <strong>ng\u00f4n ng\u1eef Razor<\/strong> \u2013 lo\u1ea1i c\u1ea5u tr\u00fac k\u1ebft h\u1ee3p HTML v\u00e0 C#. B\u1ea1n c\u00f3 th\u1ec3 h\u00ecnh dung Razor l\u00e0 m\u1ed9t d\u1ea1ng ng\u00f4n ng\u1eef t\u01b0\u01a1ng t\u1ef1 PHP nh\u01b0ng c\u00f3 c\u1ea5u tr\u00fac c\u1ee7a C#. Razor Pages t\u01b0\u01a1ng t\u1ef1 nh\u01b0 Web Pages c\u1ee7a ASP.NET.<\/p>\n\n\n\n<p>\u1ee8ng d\u1ee5ng web \u0111\u01a1n trang (<strong>SPA<\/strong>) hi\u1ec7n r\u1ea5t ph\u1ed5 bi\u1ebfn. Lo\u1ea1i \u1ee9ng d\u1ee5ng n\u00e0y s\u1eed d\u1ee5ng c\u00e1c th\u01b0 vi\u1ec7n\/framework JavaScript cho th\u00e0nh ph\u1ea7n client. C\u00e1c framework ph\u1ed5 bi\u1ebfn h\u00e0ng \u0111\u1ea7u hi\u1ec7n nay bao g\u1ed3m Angular, React. C\u00e1c lo\u1ea1i \u1ee9ng d\u1ee5ng n\u00e0y th\u01b0\u1eddng y\u00eau c\u1ea7u d\u1eef li\u1ec7u \u1edf d\u1ea1ng JSON ho\u1eb7c XML t\u1eeb c\u00e1c REST (REpresentational State Transfer) API tr\u00ean server.<\/p>\n\n\n\n<p>Tr\u00ean ASP.NET Core b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng x\u00e2y d\u1ef1ng c\u00e1c <strong>REST API <\/strong>&nbsp;nh\u01b0 v\u1eady. B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 h\u00ecnh dung REST API n\u00e0y bao g\u1ed3m th\u00e0nh ph\u1ea7n M (Model) v\u00e0 C (Controller) c\u1ee7a MVC nh\u01b0ng kh\u00f4ng c\u00f3 th\u00e0nh ph\u1ea7n V (View). Th\u00e0nh ph\u1ea7n View do b\u1ea3n th\u00e2n \u1ee9ng d\u1ee5ng SPA ch\u1ea1y tr\u00ean tr\u00ecnh duy\u1ec7t \u0111\u1ea3m nhi\u1ec7m. ASP.NET Core \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 t\u00edch h\u1ee3p m\u1ed9t c\u00e1ch li\u00ean t\u1ee5c v\u1edbi nhi\u1ec1u client-side frameworks, bao g\u1ed3m AngularJS, Knockout JS v\u00e0 Bootstrap.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C\u00f3 th\u1ec3 t\u1ea1o ra c\u00e1c \u1ee9ng d\u1ee5ng web c\u00f3 th\u1ec3 testing theo m\u00f4 h\u00ecnh MVC (Model-View-Controller) C\u00f3 th\u1ec3 x\u00e2y d\u1ef1ng HTTP services c\u00e1i m\u00e0 h\u1ed7 tr\u1ee3 nhi\u1ec1u \u0111\u1ecbnh d\u1ea1ng v\u00e0 c\u00f3 \u0111\u1ea7y \u0111\u1ee7 h\u1ed7 tr\u1ee3 cho n\u1ed9i dung c\u1ee7a d\u1eef li\u1ec7u tr\u1ea3 v\u1ec1 Razor cung c\u1ea5p m\u1ed9t ng\u00f4n ng\u1eef hi\u1ec7u qu\u1ea3 \u0111\u1ec3 t\u1ea1o Views Tag [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":5909,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-5275","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cong-nghe-thong-tn"],"_links":{"self":[{"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/posts\/5275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/comments?post=5275"}],"version-history":[{"count":2,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/posts\/5275\/revisions"}],"predecessor-version":[{"id":5910,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/posts\/5275\/revisions\/5910"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/media\/5909"}],"wp:attachment":[{"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/media?parent=5275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/categories?post=5275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trithucmoi.net.vn\/index.php\/wp-json\/wp\/v2\/tags?post=5275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}