MVC project practice, in the three-tier architecture to achieve SportsStore-11, use Knockout to add, delete, modify, query, mvc three-tier architecture

Source: Internet
Author: User
Tags tojson

MVC project practice, in the three-tier architecture to achieve SportsStore-11, use Knockout to add, delete, modify, query, mvc three-tier architecture

SportsStore is a master of ASP. the MVC project demonstrated in NET MVC3 framework (Third edition) covers many aspects of MVC, including: use DI container, URL optimization, navigation, paging, shopping cart, order, product management, Image Upload ...... it is a good MVC practice project, but it is not developed under a multi-layer framework, and there is still a distance from the real project. This series will try to implement the SportsStore project in a multi-layer framework and implement some functions in its own way.


This article is the 11th series of "Implementing SportsStore in a three-tier architecture", including:

 

■ 13. Use Knockout to add, delete, modify, and query
□13.1 about Knockout
□13.2 add, delete, modify, and query

 

13. Use Knockout to add, delete, modify, and query

13.1 about Knockout


In ASP. net mvc, for a strong View page, the View and Model are strongly coupled. The emergence of Knockout is to decouple the View and Model. Knockout is a Javascript library. It creates a View Model to decouple the View and Model. This conforms to the UI-based design mode "MVVM ":

● Model: the Domain Model of an application. In Knockout, Ajax is often used to read and write Domain Models.
● View: dynamically displays or updates the View Model UI.
● View Model: the JavaScript Object on the UI Layer and the Model on the UI Layer.

 

For more information about Knockout, see the official website. Http://knockoutjs.com/index.html

 

13.2 add, delete, modify, and query

 

The logic for adding, deleting, and modifying queries in the ProductManage controller is as follows:

using System.Linq;using System.Web.Mvc;using MySportsStore.IBLL;using MySportsStore.Model;using Ninject;namespace MySportsStore.WebUI.Controllers{    public class ProductManageController : BaseController    {        [Inject]        public IProductService ProductService { get; set; }        public ProductManageController()        {            this.AddDisposableObject(ProductService);        }        public ActionResult Index()        {            return View();        }        public JsonResult GetProducts()         {            return Json(ProductService.LoadEntities(p => true), JsonRequestBehavior.AllowGet);        }        public JsonResult AddProduct(Product product)        {            ProductService.AddEntity(product);            return Json(product, JsonRequestBehavior.AllowGet);        }        public JsonResult EditProduct(Product product)        {            ProductService.UpdateEntity(product);            return Json(ProductService.LoadEntities(p => true), JsonRequestBehavior.AllowGet);        }        public JsonResult DeleteProduct(int id)        {            var dbProduct = ProductService.LoadEntities(p => p.Id == id).FirstOrDefault();            if (ProductService.DeleteEntity(dbProduct) > 0)            {                return Json(new {msg = true},JsonRequestBehavior.AllowGet);            }            return Json(new { msg = false }, JsonRequestBehavior.AllowGet);        }    }}

In the ProductManage/Index. cshtml View:
@ {Layout = null ;}<! DOCTYPE html> 

 

The source code is here.

 

The series "MVC project practices, implementing SportsStore in a three-tier architecture" includes:

MVC project practice, realize SportsStore under the three-tier architecture, view the three-tier architecture MVC project practice from the class diagram, implement SportsStore-01 under the three-tier architecture, EF Code First modeling, DAL layer and other MVC project practices, under the three-tier architecture to achieve SportsStore-02, DbSession layer, BLL layer MVC project practice, in the three-tier architecture to achieve SportsStore-03, Ninject controller factory MVC project practice, in the three-tier architecture to achieve SportsStore-04, implementation of paging MVC project practice, in the three-layer architecture to achieve SportsStore-05, to achieve the navigation MVC project practice, in the three-layer architecture to achieve SportsStore-06, to achieve the shopping cart MVC project practice, in the three-layer architecture to achieve SportsStore-07, implementation of order to submit MVC project practice, in the three-tier architecture to achieve SportsStore-08, deployment to IIS server MVC project practice, in the three-tier architecture to achieve SportsStore-09, ASP. net mvc calls ASP. NET Web API query service MVC project practice, in the three-tier architecture to achieve SportsStore-10, connection string encryption and decryption MVC project practice, in the three-tier architecture to achieve SportsStore-11, use Knockout to achieve addition, deletion, modification, query
An mvc project is injected with the ext js framework to add, delete, modify, and query.

Add, delete, modify, and query.
 
How Should SpringMVC be configured? In this case, it is best to add, delete, modify, and query MYSQL Data in two tables.

Elf8848.iteye.com/blog/875830/ study it yourself, ka
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.