我正在使用 ASP MVC 5 并尝试在“ControlPanel”区域内的视图中生成链接
我的视图 rootfolder/Areas/ControlPanel/Views/CourseCategory/Index.cshtml
@Html.ActionLink("edit", "Edit", new { id = item.Id }, new { @class = "btn btn-default btn-xs" })
@Html.ActionLink("delete", "Delete", new { id = item.Id }, new { @class = "btn btn-danger btn-xs" })
我的区域注册
public class ControlPanelAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "ControlPanel";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.LowercaseUrls = true;
context.MapRoute(
name: "ControlPanel.CourseCategory",
url: "controlpanel/course-categories/{id}",
defaults: new { controller = "CourseCategory", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Website.Areas.ControlPanel.Controllers" }
);
}
}
路由配置文件
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.LowercaseUrls = true;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "HomePage",
url: "",
defaults: new { controller = "Home", action = "Index" }
);
}
}
我的控制器
namespace Website.Areas.ControlPanel.Controllers
{
public class CourseCategoryController : ControlPanelController
{
public CourseCategoryController(IUnitOfWork uow)
:base(uow)
{
}
public ActionResult Index()
{
return View(_uow.Repository<CourseCategory>().GetAllOrderByCode());
}
}
}
现在输出html产生空href
<a class="btn btn-default btn-xs" href="">edit</a>
<a class="btn btn-danger btn-xs" href="">delete</a>
在这种情况下,在 Html.ActionLink 或 Url.Action 和 Url.RouteUrl 上生成链接的正确方法是什么?