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 filenamepath conventions for project files (referencing them from *.aspx and *.html).
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"
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.AspViewsHomeShowCuteDog.html how do I a href
the html file from within index.aspx?
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);
}
}
}
I also created VIEWS but they too long to post here. I will continue my explanation showing the body
of 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>
Obviously the path to ShowCuteDog.html is invalid. However, it seems no matter what I do I cannot enter a valid path.
I would like to know how to open ShowCuteDog.html using the a href
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?)
Thank you in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…