这个问题与 VS 2010 中 MVC 项目文件夹中的 MVC 框架和文件排列约定有关。它还与项目文件的文件名\路径约定(从 *.aspx 和 *.html 引用它们)有关。
为了帮助回答这个问题,我创建了一个名为“PAPlus.Asp”(虚构名称)的示例项目。重现步骤:打开VS2010SP1Rel->File->NewProject->ASP.Net MVC 2 Empty Web Application->Name = "PAPlus.Asp"
我的问题是:如果我创建一个 MVC 2.0 应用程序(下面的示例)并想要链接位于我的项目文件夹中的 *.html 文件 ..\PAPlus.Asp\Views\Home\ShowCuteDog.html 我该怎么做a href
index.aspx 中的 html 文件?
我正在使用以下数据提供者:
<connectionStrings>
<add name="PaPlus"
connectionString="Data Source=|DataDirectory|PAPlus.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
我创建了以下内容:
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);
}
}
}
我还创建了 VIEWS,但它们太长了,无法在此处发布。我将继续我的解释显示body
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>
解释完上述所有内容后,我可以针对需要帮助的特定行:
<a href="Views/Home/ShowCuteDog.html">Navigate to Cute Dog Page!</a>
显然 ShowCuteDog.html 的路径是无效的。但是,似乎无论我做什么,我都无法输入有效路径。
我想知道如何使用打开 ShowCuteDog.htmla href
我还想知道在我的 MVC 项目解决方案文件夹结构中应该将 ShowCuteDog.html 存储在哪里(/Views/Home/ 似乎是最好的地方,也许我错了?)
先感谢您。