There are at least two different ways you can do it.
First one (better one) is using a Model to pass data. For that you should create a Model class:
//Model.cs
public class MyModel
{
public bool UserCanCreate { get; set;}
}
and specify it at the beginning of your View (use typed view):
@model %Your_model_namespace%.MyModel
...
<p>
@if (Model.UserCanCreate)
{
@Html.ActionLink("Create New", "Create")
}
And, of course, in your controller action do the following:
public ActionResult YourAction()
{
...
MyModel model = new MyModel();
model.UserCanCreate = ... ; // Determine if link shall be visible here
...
return View(model);
}
Second (faster one, although not recommended): use ViewData collection to pass values.
For example, in your controller action do:
public ActionResult YourAction()
{
...
ViewData["UserCanCreate"] = ... ; // Determine if link shall be visible here
...
return View();
}
and your view will look like:
...
<p>
@if ((bool)ViewData["UserCanCreate"])
{
@Html.ActionLink("Create New", "Create")
}
Also important: if you're trying to secure some actions that way then do not forget to add some checks for permissions inside "Create" action code - otherwise any user will be able to execute it by just entering corresponding URL in browser address bar - even if the ActionLink is not present.
UPDATE
As for your comment - you seem to be mixing domain models with view models. Domain models are the ones that represent your database entities, while view models are the ones that should be used for presentation. Generally it's controller's job to convert objects from domain to view models and vice versa.
In your case EF models are domain models.
For ViewModel you should create a separate class which will aggregate your domain model instance and any additional properties you want - like UserCanCreate.
Example model class:
public class UsersViewModel
{
public IEnumerable<DBName.Models.Users> Users { get; set; }
public bool UserCanCreate { get; set; }
... // Any other additional properties you may require
}
In your controller it will be:
public ActionResult YourAction()
{
...
UsersViewModel model = new UsersViewModel();
model.Users = ... ; // Get your IEnumerable<DBName.Models.Users> collection from DB and assign it to model property here
model.UserCanCreate = ... ; // Determine if link shall be visible here
...
return View(model);
}
and in view:
@model %Your_model_namespace%.UsersViewModel
... // use Model.Users wherever you need your IEnumerable<DBName.Models.Users>
<p>
@if (Model.UserCanCreate)
{
@Html.ActionLink("Create New", "Create")
}