我是MVC的新手.我希望能够为某些用户隐藏一些动作链接.假设我有一个"创建"动作链接,我只希望管理员查看并单击.我想在asp.net中使用某种"loggedmpmplate",但它似乎不适用于剃须刀.
我可以使用某种代码块和if语句检查当前用户及其角色,但这可能不是最佳做法?
我的index.cshtml ..
// want some adminauth attribute here...
@Html.ActionLink("Create New", "Create")
Run Code Online (Sandbox Code Playgroud)
我的控制器..
// GET: /Speaker/Create
[Authorize(Roles = "Administrators")]
public ActionResult Create()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)