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 6900361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:12+00:00 2026-05-27T07:32:12+00:00

I am trying to render a partial view in my Site.Master file but I

  • 0

I am trying to render a partial view in my Site.Master file but I keep on getting an error (Object reference not set to an instance of an object). If I access the view directly, I get the info that I need, but if I access the Index View from the HomeController, I get an error. The partial view will display the logged in user, department, and role. This is my code.

Controllers Folder
-HomeController.cs
-UsersController.cs

Models
-Repository Folder
  - UersRepository.cs
-Repository Interface Folder
  - IUsers.cs
-Service Folder
  - UsersService.cs
  - IUserService.cs
-Validation Folder
  - IValidationDictionary
  - ModelStateWrapper

The view that I’m trying to partially render is called LoginInfo.ascx and it’s located in the Shared Folder.

LoginInfo.cs Code:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Users>>" %>

<%@ Import Namespace="TimeAttendanceMVC.Models"%>




<table>
    <tr>
        <th>
            UserName
        </th>
        <th>
            Department
        </th>
        <th>
            UserType
        </th>

    </tr>

<% foreach (var item in Model) { %>
    <tr>
        <td>
            <%: Html.DisplayFor(modelItem => item.UserName) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Department) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.UserType) %>
        </td>

    </tr>
<% } %>

</table>

Site.Master Code:

   <% Html.RenderPartial("LoginInfo"); %>

UserController.cs

 public class UsersController : Controller
    {
        //
        private IUsersService _service;

        //==============================================================================
        //==============================================================================
        public UsersController()
        {
          _service = new UsersService(new ModelStateWrapper(this.ModelState));
         }

        public UsersController(IUsersService service)
        {
            _service = service; 
        }

        //==============================================================================
        //==============================================================================
        // GET: /Employee/
        //==============================================================================
        //==============================================================================
        // GET: /Employee/
        public ActionResult Index()
        {

            var model = _service.Return_UserName_Dept();
            return View("LoginInfo", model);
        }

    }

HomeController.cs

 public ActionResult Index()
        {
            //var model = _service.Return_UserName_Dept();
            //return View(model);
            return View();

        }

With the code above, I get an error. If I un-comment the 2 lines in my HomeController and I pass the model to the View, then it works fine. But my HomeController will need a different model, so how will I pass 2 models to the View?

Any ideas what I’m doing wrong? I’m still learning MVC right now so I’m not that good at this. Any help would be appreciated. Thanks.

  • 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-27T07:32:13+00:00Added an answer on May 27, 2026 at 7:32 am

    Calling RenderPartial renders the view directly, inheriting the parent’s model.

    You should call RenderAction instead to render a child action so that the action can pass the correct model to the partial view.

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

Sidebar

Related Questions

Background I'm receiving the following error when trying to render a partial view in
I'm trying to create a strongly typed partial view <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master
I'm trying to render a partial view on my master page using Html.RenderAction() in
I'm trying to render a partial within a view. When calling the render I'm
So I am trying to render a partial view into my page and I
i am trying to use a Html.RenderPartial but getting an error: 'Using' must end
I'm trying to render a partial ascx view within another view. I have the
I'm trying to use MVC2 client-side validation in a partial view that is rendered
I am trying using a partial to render the application's menu, capitalizing the 'tab'
I am trying to upload images via a form which sits in partial view

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.