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

  • Home
  • SEARCH
  • 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 7732341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:42:25+00:00 2026-06-01T06:42:25+00:00

I’m building MVC3 code first application and to display data on my page I’m

  • 0

I’m building MVC3 “code first” application and to display data on my page I’m using the following:
Controller Code:

public ViewResult Index()
{
dynamic assignedT = from t in db.AssignedTasks

join a in db.Approvers on t.ApproverID equals a.ID
 join r in db.Requestors on t.RequestorID equals r.ID
 select new {Approver =a.FirstName + " " +a.LastName,
 Requestor=r.FirstName + " " + r.LastName,
 Title = t.Title,
 t.RequestedDate,
 t.CompletedDate, t.Description,
 Status =(int)t.InternalStatut
  };

 return View(assignedT);
    }

and on the page:

@{
   ViewBag.Title = "Index";
 }
<h2>Index</h2>
 <table>
  @foreach (var item in Model) {     
 <tr> 
   <td>@item.GetType().GetProperty("Title").GetValue(item, null)
   </td> 
   </tr> 
   } 
</table>

I know that using dynamic is not the best way.
How to achieve same functionality using strongly-typed view?
Thank you

  • 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-06-01T06:42:26+00:00Added an answer on June 1, 2026 at 6:42 am

    You can define the following class:

    public class MyViewModel
    {
        string Approver { get; set; }
        string Requestor { get; set; }
        string Title { get; set; }
        DateTime RequestedDate { get; set; }
        DateTime CompletedDate { get; set; }
        string Description { get; set; }
        int Status { get; set; }
    }
    

    If you then change select new in your Linq query to select new MyViewModel then you have a strongly typed viewmodel (and dynamic to var).

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

Sidebar

Related Questions

I am currently building my first MVC 3 application, using EF Code First, SQL
I'm building a simple code-first MVC 3 blog like application. My model has three
I am building wizard step demo application with MVC3 and using razor view engine
I'm building a web application using MVC3 and I'm wondering what the etiquette is
We are currently building a mid-sized intranet application using MVC3. One requirement is the
I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
I'm building an MVC3 application using the Entity Framework. In the application my controllers
I am building an application using MVC3, Razor view engine, Repository Pattern with Unit
Just started learning mvc3. I've built a fairly basic website (also using EF-Code-First if
I'm building an e-commerce site using C#, MVC3, Entity Framework 4, my first stab

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.