0

I am just starting with MVC, moving from web forms.

Lets take for example:

I have a page that shows a list of contacts with properties such as first name, last name, company, phone, email address, etc....

On that page, a user role determines if they can see particular columns. So an admin could see the phone and name while a basic user could only see company, address and a few others.

Would you toss that logic into a view or have the controller do the logic and use another view?

Seems to me that making the controller would be the best but the views could get repititve.

Thanks for the help, trying to wrap my ahead around it.

(Any good book recomendation are welcome, trying to read a few.)

1
  • Look at the nerddinner.codeplex.com sample for a Great start in MVC Commented Nov 13, 2011 at 23:35

1 Answer 1

1

I'd have two FormViewModels.

The first containing columns the Admin can see and the second with columns a basic user can see.

I'd implement an interface and use that as the model for the view.

Then in the controller, I'd return one or the other depending.

You might consider using a partial view for each type of user and then simply;

<% if (user.isAdmin){ %>
  <% Html.RenderPartial("Admin", model); %>
<%} else {%>
  <% Html.RenderPartial("BasicUser", model); %>
<%}%>

The other way to do this is to maybe have the view do this and you can create a helper class to check to see if the user is an admin

<% if (user.isAdmin){ %>
  //Column for admin
<%}%>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.