zoukankan      html  css  js  c++  java
  • 页面文件非得放在Views目录下边吗?

     查看相差文档后代码以及动手实践后证明,标题的答案是否定的。

    不过官方文档说的比较简单,也没提供相差配置说明,最后发现Controll.View(sting)的一个重载可以定位到其它的文件,但也没有具体展开

    说明参数的具体规则。

    具体规则如下:

    相对控制器目录的名称规则:

    一种是相对ControllerContext的。 

    比如有个HomeController,则可以直接指定相对Home目录的路径名称,不带.aspx后辍。这个比较容易理解。

     using System;

    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using HelloWorld.Models;

    namespace HelloWorld.Controllers
    {
        
    public class HomeController : Controller
        {

            
    public ActionResult Test()
            {
                
    return View("MyTest");//~/views/home/mytest.aspx
            }

            
    public ActionResult Test()
            {
                
    return View("My/Test");//~/views/home/my/test.aspx
            }


        }
    }

     另一种是相对HttpContent的。

    这种方式下的参数内容就是相对应用的程序要目录的文件路径,需要带.aspx后辍。比如~/My/Test.aspx,其代码如下:

    public ActionResult Test()
            {
                
    return View("~/My/Test.aspx");//
            }
  • 相关阅读:
    Struts数据效验
    Struts2中国际化
    ValueStack对象
    Ognl表达式语言
    Struts2拦截器
    ubuntu下tomcat运行不起来解决
    Windows 下的SSH客户端
    远程管理控制ssh
    linux用户和组账户管理
    搭建Java服务器,并且实现远程安全访问linux系统
  • 原文地址:https://www.cnblogs.com/icoolno1/p/1867241.html
Copyright © 2011-2022 走看看