I am beginner in MVC 4, I am facing problem to achieve one simple requirement. The problem described as below.
I have 3 roles(Programmer,reviewer,Admin) and 1 razor view, that has 4 panels and each panel has set of controls , depends on the role and the some condition i have to make panels visible false/true.
Please help me out.
Thanks and regards
Vishwa
Vishwa LPosted Mar 31, 2013, 10:08 PM
Jignesh TrivediPosted Mar 29, 2013, 12:18 AM
hi,
main advantage of MVC is you can render any view from any controller action.
you requirement is fullfil by two way.
first create differnt views for differnt role. these view contain only those panels with you want to show.
for example we have 3 roles like role1,role2 and role3 and four panel like panel1,panel2,panel3 and panel4
then create 3 differnt view and put respective panel if role1 is contain right for panel 1 and panel 2 than put only this two panel with in view 1. now depending upon the condition render respective view from controller.
public ActionResult PreviewOutputFile(EntryAmendmentFileModel item)
{
if(role =="role1")
{
return View("view1");
}
else if(role =="role2")
{
return View("view2");
}
else if(role =="role3")
{
return View("view3");
}
}
second way is create single view and put contion with in view.
<% if (Role == "role1")
{ %>
write your pannel HTML
<%
}
%>
hope this will help you.