登录布局

150 阅读1分钟

创建控制器

image.png

布局视图

image.png

效果展示

image.png

验证码模块

image.png

MVC基础

命名规范

  • Controllers: 控制器创建的控制器必须以Controller结尾,控制器里有若干行为(方法)控制相应的页面,相应的操作;
  • View: 控制器HomeController创建后,View层会自动创建对应Home文件夹,来存放相对行为的视图;
  • Model:视图模型,以ViewModel结尾,例如:HomeViewModel,也叫业务模型,与数据访问层的数据模型经行交互,返回用户所需要的数据

如何获取页面传过来的参数值

  • ?号传参
    location.href ="Index?id="+id
复制代码
复制代码
    public ActionResuLt Index(string id)
    
    {
        string id = Request["id"].toString();//get post
        string id = Request.QueryString["id"];//get
        string id = Request.Files["id"].ToString();
    }
复制代码
复制代码
  • 路由传参
    location.href ="Index/id"
复制代码
复制代码
    public ActionResuLt Index(string id)
    
    {
        string id =RoutoData.Values["id"]//get post
    }
复制代码
复制代码

五、返回视图

    public ActionResult Index()
    {
        return View();//返回默认的视图,即和方法名一样的View视图
        return View("Show")//返回在同一视图文件夹下的Show视图
        return VIew("`/Views/Shop/ShopList")//返回指定路径的视图
    }


作者:用户1285995868385
链接:juejin.cn/post/705361… 来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。