I'm not sure if this is the right way but this could work.
Solution1
You can have a boolean
in your model to check if a user is in certain role and then create a view based upon that model
For example.
public class MyViewWithCustomAuthentication
{
....
public bool IsAdmin{get;set;}
...
}
in your controller you can check if the user is in certain role
public ActionResult Index()
{
var myView = new MyViewWithCustomAuthentication();
myview.IsAdmin = false;
if(User.IsInRole("Admin"))
{
myView.IsAdmin = true;
}
return View(myView);
}
then in view
@model MyViewWithCustomAuthentication
....
@if(Model.IsAdmin == true)
{
//show HTML
}
else
{
//hide HTML
}
....
Here you will have one view but you may have to make a small change in your viewmodel as I mentioned.
Solution 2
Another way could be to check if user is in certain role and create different views for different roles, based upon the requirement. This way you can show the desired HTML but then you'll end up having different views.
public ActionResult Index()
{
if(User.IsInRole("Admin"))
{
return View("ViewForAdmin")
}
return View("ViewForNonAdmin");
}
If anyone has any suggestions feel free to edit or comment.