• 一套解决方案,多个项目


    控制器

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using SportsStore.Domain.Abstract;
    using SportsStore.Domain.Entities;
    
    namespace SportsStore.WebUI.Controllers
    {
    
        public class ProductController : Controller
        {
            private IProductRepository repository;
    
            public ProductController(IProductRepository productRepository)
            {
                this.repository = productRepository;
            }
    
            public ViewResult List()
            {
                return View(repository.Products);
            }
        }
    }
    

    视图层

    @using SportsStore.Domain.Entities
    @model IEnumerable<Product>
    
    @{
        ViewBag.Title = "Products";
    }
    
    
    @foreach (var p in Model)
    {
        <div>
            <h3>@p.Name</h3>
            @p.Description
            <h4>@p.Price.ToString("c")</h4>
        </div>
    }
    

    修改默认路由

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace SportsStore.WebUI
    {
        public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Product", action = "List", id = UrlParameter.Optional }
                );
            }
        }
    }
    
    

    操蛋玩意,不懂。

  • 相关阅读:
    使用JS获取上一页的url地址
    禁止弹窗中蒙层底部页面跟随滚动的几种方法汇总
    一个Option请求引发的深度解析
    html li标签前面添加图标三种方法
    CSS3
    计算x
    计算圆周率
    最长公共子序列
    小字辈(左子右兄加强版)
    Excel列名和列序号转换
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/6956555.html
Copyright © 2020-2023  润新知