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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:44:08+00:00 2026-06-04T00:44:08+00:00

Answered Dbaseman was correct but to simplify it all, I don’t need a modal

  • 0

Answered

Dbaseman was correct but to simplify it all, I don’t need a modal and my code looks like this now:

[ChildActionOnly]
public ActionResult RecentNews()
{
    return PartialView(db.Articles.ToList());
}

and

@{Html.RenderAction("RecentNews");}

Below is my old code that wasn’t working

I’m having trouble getting the following to work, I’m unsure if I’m even close to being on the right track or not. The code all works fine if I create a View but not if I create a partial View and add it to other views. Whatever I try I seem to get the error : Object reference not set to an instance of an object.

In my view I have:

@Html.Partial("RecentNews")

My action looks like this:

public ActionResult RecentNews()
{
    var rn = (from m in db.Articles
                select new RecentNews
                {
                    ArticleHeading = m.ArticleHeading
                });
    return View(rn);

    //return View(db.Articles.ToList());
}

My modal:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace melbournesportsstadium.Models
{
    public class RecentNews
    {
        public string ArticleHeading { get; set; }
    }
}

And my RecentNews.cshtml:

@model List<melbournesportsstadium.Models.RecentNews>

<table>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ArticleHeading)
        </td>
    </tr>
}

</table>

Can someone please help me get this working?

  • 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-04T00:44:10+00:00Added an answer on June 4, 2026 at 12:44 am

    You’re getting “null reference” because the partial view is not receiving any model; @Html.Partial doesn’t return to the controller, it renders the view directly. Change it to @Html.Action(“RecentNews”) and it should work.

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

Sidebar

Related Questions

I have answered this sort of in a previous question but now I have
this might have been answered or might be too easy, but I haven't found
Sorry if this been answered before, but i can't find an answer here. How
I've answered two different questions now, both explaining how VOIP apps don't start on
This question have been answered. I recommend sumit_programmers solution below. For now, I've removed
This may have been answered elsewhere but I could not find a suitable response.
This has probably been answered else where but how do you get the character
This was answered for XCode 3, but not XCode4. Answer for XCode3 has not
Answered: What is proper ruby ffi code for this function: void glutInit(int *argc, char
[answered] I'm testing my browser's fps for an html5 game. I have this code:

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.