zoukankan      html  css  js  c++  java
  • .Net视图机制

    .Net会有默认的约定。

    HomeController下面的Index,会默认渲染Home/Index.cshtml。

    当然可以设置成别的,比如设置成About。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace mvcDemo.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewBag.Message = "I like milk.";
                return View("About");
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "I like cake.";
    
                return View();
            }
    
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
        }
    }
    

    这样首页就使用了About的视图页面了。

    视图被控制器渲染,控制器提供视图数据,这是.Net约定俗成的。

    改为完整路径,

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace mvcDemo.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewBag.Message = "I like milk.";
                return View("~/Views/Home/About.cshtml");
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "I like cake.";
    
                return View();
            }
    
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
        }
    }
    
  • 相关阅读:
    arcgis对谷歌遥感影像拼接
    animation动画
    通过$ref设置样式
    Element drawer添加 滚动条 无法上下滚动
    ECharts 点击事件的 param参数
    解析后台参数
    .NET Core中具有多个实现的依赖注入实现
    玩转Firefox侧栏
    实用AutoHotkey功能展示
    利用7z实现一键解压
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/6874865.html
Copyright © 2011-2022 走看看