我有以下文件夹结构:Controller/EntityController Views/Entity/Index.cshtml Views/Shared/DisplaTemplates/CustomEntity.cshtml
实体控制器:
public ActionResult Index()
{
var entities = CustomEntityRepository.GetAll();
return View(entities);
}
public ActionResult Edit(int id)
{
if (id == 0)
{
return HttpNotFound();
}
var entity = CustomEntityRepository.Find(e => e.ID == id);
return View(entity);
}
Index.cshtml的内容:
@model IEnumerable<CustomEntity>
@{
ViewBag.Title = "Index";
}
@Html.DisplayForModel()
CustomEntity.cshtml 的内容:
@model CustomEntity
<div>
Entity:
<strong>@Model.Name</strong>
@Html.ActionLink("Show All","Edit","Entity", new { id= @Model.ID}, null)
@Html.LabelFor(m=>m.Icon):
@Model.Icon
@Html.LabelFor(m=>m.TypeName):
@Model.TypeName
</div>
编辑: 路由配置:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
但是,ActionLink 并没有按我预期的方式工作。我希望 ActionLink 使用每个实体提供的 ID 指向 EntityController Edit 操作。相反,它呈现以下网址:
http://localhost/MySite/Reports?action=Edit&controller=Entity&id=1
我不知道 /Reports/ 来自哪里。
谢谢!