0
我在我的網站上有爲前端創建/編輯/刪除頁面的功能。這裏是我的控制器:創建Html.ActionLink到動態內容頁面
namespace MySite.Controllers
{
public class ContentPagesController : Controller
{
readonly IContentPagesRepository _contentPagesRepository;
public ContentPagesController()
{
MyDBEntities entities = new MyDBEntities();
_contentPagesRepository = new SqlContentPagesRepository(entities);
}
public ActionResult Index(string name)
{
var contentPage = _contentPagesRepository.GetContentPage(name);
if (contentPage != null)
{
return View(new ContentPageViewModel
{
ContentPageId = contentPage.ContentPageID,
Name = contentPage.Name,
Title = contentPage.Title,
Content = contentPage.Content
});
}
throw new HttpException(404, "");
}
}
}
而且在我的Global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Page", // Route name
"Page/{name}", // URL with parameters
new { controller = "ContentPages", action = "Index" }, // Parameter defaults
new[] { "MySite.Controllers" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "MySite.Controllers" }
);
}
所以我有一個動態的網頁在我的數據庫,命名關於。如果我轉到mysite.com/Page/About,我可以查看動態內容。
我想創建一個ActionLink到這個頁面。我試着這樣說:
@Html.ActionLink("About Us", "Index", "ContentPages", new { name = "About" })
但是,當我看到頁面上的鏈接,鏈接只是去到當前頁面的查詢字符串Length=12
。例如,如果我在主頁上,鏈接將轉到mysite.com/Home?Length=12
我在這裏做錯了什麼?