如何从.aspx页面中引用的.html页面在同VS2010的解决方案? [英] How to reference .html page from .aspx page in the same VS2010 solution?

查看:773
本文介绍了如何从.aspx页面中引用的.html页面在同VS2010的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该问题与2010年它还具有对项目文件的文件名\\路径约定(从*的.aspx和*。html的引用它们)做了VS MVC项目文件夹中的MVC框架和文件安排约定办

This question has to do with the MVC framework and file arrangement conventions within the MVC project folders in VS 2010. It also has to do with filename\path conventions for project files (referencing them from *.aspx and *.html).

要协助回答我创建了名为PAPlus.Asp(一个虚构的名称)的样本项目的问题。重现步骤:打开VS2010SP1Rel->文件 - > NewProject-> ASP.Net MVC 2空Web应用程序 - > NAME =PAPlus.Asp

To assist in answering the question I created a sample project titled "PAPlus.Asp" (a made-up name). Steps to reproduce: open VS2010SP1Rel->File->NewProject->ASP.Net MVC 2 Empty Web Application->Name = "PAPlus.Asp"

我的问题是这样的:如果我创建一个MVC 2.0应用程序(下面的例子),并希望链接* .html文件是在位于.. \\ PAPlus.Asp \\我的项目文件夹视图\\首页\\ ShowCuteDog.html我怎么 A HREF HTML文件从内部的Index.aspx?

My question is this: if I create a MVC 2.0 application (example below) and want to link a *.html file that is in my project folder located at ..\PAPlus.Asp\Views\Home\ShowCuteDog.html how do I a href the html file from within index.aspx?

我用下面的DataProvider:

I am using the following DataProvider:

  <connectionStrings>

    <add name="PaPlus"
         connectionString="Data Source=|DataDirectory|PAPlus.sdf"
         providerName="System.Data.SqlServerCe.4.0"/>

  </connectionStrings>

我创建了以下内容:

I created the following:

namespace PAPlus.Asp.Models
{
    public class User
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
    }
}

namespace PAPlus.Asp.Models
{
    public class PaPlus : DbContext
    {
        public DbSet<User> Users { get; set; }
    }
}

namespace PAPlus.Asp.Controllers
{
    public class HomeController : Controller
    {
        PaPlus _paPlus = new PaPlus();

        public ActionResult Index()
        {
            var users = from u in _paPlus.Users
                        select u;

            return View(users);
        }

    public ActionResult Create()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Create(User newUser)
    {
        if (ModelState.IsValid)
        {
            if (_paPlus.Users.Any(d => d.UserName == newUser.UserName))
            {
                ModelState.AddModelError("UserName", "The username is not unique");
                return View(newUser);
            }

            _paPlus.Users.Add(newUser);
            _paPlus.SaveChanges();

            return RedirectToAction("Index");
        }

        return View(newUser);

    }

}
}

我还创建了意见,但他们太长时间在这里发表。我会继续我的解释显示的Index.aspx的

<body>
    <div>   
        <h1>Application Users</h1>
    <ul>    
    <%
        foreach (User d in Model)
        {%>
        <li> 
            <%=d.UserName%> (<%=d.UserId%>)
        </li>
    <%
        }%>
    </ul>
    <p>
        <%=Html.ActionLink("Create New User", "Create")%>
    </p>
    <p>
        <a href="Views/Home/ShowCuteDog.html">Navigate to Cute Dog Page!</a>
    </p>
    </div>
</body>

对于所有解释上述情况,我可以定位我想与援助的特定行:

With all of the above explained, I can target a specific line that I would like assistance with:

<a href="Views/Home/ShowCuteDog.html">Navigate to Cute Dog Page!</a>

显然的路径ShowCuteDog.html是无效的。然而,似乎不管我做,我不能输入一个有效的路径。

Obviously the path to ShowCuteDog.html is invalid. However, it seems no matter what I do I cannot enter a valid path.

我想知道如何使用打开ShowCuteDog.html的 A HREF

I would like to know how to open ShowCuteDog.html using the a href

我也想知道我要我的MVC项目解决方案文件夹结构中存储ShowCuteDog.html(/浏览/首页/似乎是最好的地方,也许是我错了吗?)

I would also like to know where I should store ShowCuteDog.html within my MVC project solution folder structure (/Views/Home/ seems like the best place, perhaps I am wrong?)

感谢您提前。

推荐答案

您不应该把下将直接链接查看的内容。这条道路的浏览器访问被阻止在查看/ web.config中默认情况下,并有很好的理由:你不这样做的希望的用户直接加载从那里的文件。

You should not put content under Views that will be directly linked. Browser access to that path is blocked in Views/web.config by default, and for very good reasons: you don't want users directly loading files from there.

所以,你应该把普通的HTML别的地方;也许在 / HTML 呢?然后连接为&LT; A HREF =/ HTML / cutepuppies.html&GT;

So you should put plain html somewhere else; perhaps in /html instead? Then link it as <a href="/html/cutepuppies.html">

这篇关于如何从.aspx页面中引用的.html页面在同VS2010的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆