所有进出口试图做的就是我的网址有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