c# - ASP.NET MVC - Get database data depending user role -
i'm new mvc , database stuff.
what need retrieve data depending on user's role. can data table below need show specific data.
tableid roleid data1 data2 data3 1 1 data data data 2 1 data data data 3 1 data data data 4 2 data data data 5 2 data data data 6 3 data data data
so if user logged in , assigned role, how fetch data table role? if assigned roleid 1, should see data table roleid = 1.
i'm still learning , awesome help.
thanks!
my code:
controller
private projectentities db = new projectentities(); // get: /assessment/ public actionresult index() { //return view(db.scales.tolist()); var data = new modelservices().getscale(); return view(data); }
model
public class modelservices : idisposable { private readonly projectentities entities = new projectentities(); public ienumerable getscale() { return entities.scales.tolist(); } public void dispose() { entities.dispose(); } }
view:
@model ienumerable<project.models.scale> @{ webgrid grid = new webgrid(model); } @grid.gethtml()
i'd create new services method so:
public ienumerable<scale> getscaleswithrole(int roleid) { return entities.scales.where(s => s.roleid == roleid).tolist(); }
Comments
Post a Comment