Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:26:45+00:00 2026-05-31T20:26:45+00:00

I have a problem, I have the next controller namespace RolesMVC3.Areas.Administrador.Controllers { [Authorize(Roles =

  • 0

I have a problem, I have the next controller

namespace RolesMVC3.Areas.Administrador.Controllers
{
    [Authorize(Roles = "Adminr")]
    public class HomeController : Controller
    {
        private BASEDATOSCJ_2Entities db = new BASEDATOSCJ_2Entities();
        public ActionResult Index()
        {   
            string username = User.Identity.Name;
            MembershipUser user = Membership.GetUser(username);
            Guid key = (Guid)Membership.GetUser().ProviderUserKey;

            var Universities = (from u in db.UNIVERSITy
                                 join s in db.CAMPUS_UNIVERSITy on u.IdUniversity equals s.IdUniversity
                                 join c in db.CIUDAD_CAMPUS on s.IdCiudadSede equals c.IdCiudadSede
                                 join co in db.OFFICE on s.Idoffice equals co.Idoffice
                                 join uxc in db.USERxOFFICE on co.Idoffice equals uxc.Idoffice
                                 where uxc.UserId == key
                                 select new { u.Name, namecity = c.Nombre, s.Idoffice}).ToList();
            return View(Universities);
        }

With this controller I just want send to View u.Name, and s.Idoffice. How I do? (in fact do not know if this controllet is fine), I want to send fields belong to different tables. I want to send the query as a list and present at the View, ViewBag go with it?, How do I pass these data to the view and display with a foreach?.

I use razor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:26:46+00:00Added an answer on May 31, 2026 at 8:26 pm

    I would use a view model. I have learnt not to expose my domain objects to the view, I rather map my domain object to the view model and return this view model to the view.

    Separate you data access logic from your view logic. You can put that whole statement into a repository class and then you just call this method from the controller.

    Here is a partial view model, you might have more properties if you need more data to be displayed:

    public class UniversityViewModel
    {
         IEnumerable<University> Universities { get; set; }
    }
    

    University class:

    public class University
    {
         public string Name { get; set; }
         public string Idoffice { get; set; }
    }
    

    In my action method of my controller it would look something like this:

    public ActionResult Index(int id)
    {
         UniversityViewModel viewModel = new UniversityViewModel
         {
              Universities = universityRepository.GetAll()
         };
    
         return View(viewModel);
    }
    

    And in my view I would have the following:

    <table>
    
    @foreach(University university in Model.Universities)
    {
         <tr>
              <td>Name:</td>
              <td>university.Name</td>
         </tr>
    }
    
    </table>
    

    This is just a basic display of data in the view, you can use 3rd party components to display your data with some features.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the next problem: I need to process only 1 request at a
I have the next problem. In one of the cells (UITableViewCell) I need to
I'm trying to get a regexp to solve the next problem: I have some
Greetings, I have problem with errorPlacement, I'm trying to place the error message next
I have the following problem: We need to find the next august. I other
I have a small problem where I want to find the next active item
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a model class like following public class ProductModel { string ProductName {
I have a problem trying to edit. I work with Areas for better management

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.