所有進出口試圖做的就是我的網址有blogid追加到它很像下面...MVC4剃鬚刀 - 試圖讓ID在URL的博客文章
http://localhost/blog/blogpost/17
這裏我的控制器......
public ActionResult BlogList(){ return View(_repository); }
public ActionResult BlogPost(string id)
{
ViewData["id"] = id;
if (ModelState.IsValid)
{
return RedirectToAction("BlogPost", new { id = id });
}
return View(_repository);
}
現在,這裏是我的route.config圖路線
routes.MapRoute(
"MyBlog", // Route name
"blog/{action}/{id}", // URL with parameters
new { controller = "Blog", action = "blogpost", id =
UrlParameter.Optional } // Parameter defaults
);
現在我可以摹等我點擊博客列表中的博客時出現的網址。該頁面不顯示博客,它顯示重定向循環消息。如果我省略以下代碼...
if (ModelState.IsValid)
{
return RedirectToAction("BlogPost", new { id = id });
}
然後我可以顯示博客。該網址不會有id值。像這樣...
http://localhost/blog/blogpost/
我在做什麼錯?
更新了我的答案 –
任何人都可以在這方面幫助?我完全失去了這一點。人們不斷給我答案,我不明白爲什麼。任何人都可以給我詳細的信息或解釋爲什麼我不能附加一個ID到我的URL像上面。我被告知刪除我無法做的BlogList,因爲它正在使用中。 – user3036965