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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:33:05+00:00 2026-06-14T14:33:05+00:00

I wrote a partial method like this : public ActionResult _StatePartial() { ViewBag.MyData =

  • 0

I wrote a partial method like this :

public ActionResult _StatePartial()
        {
            ViewBag.MyData = new string[] { "110", "24500" };
            return View();
        }

And render _StatePartial view in _Layout page:

@Html.Partial("_StatePartial")

This is my partial view code:

@{
    string[] Data = (string[])ViewBag.MyData;
}
<div id="UserState">
        Reputation: @Html.ActionLink(Data[0], "Reputation", "Profile") | 
        Cash: @Html.ActionLink(Data[1], "Index", "FinancialAccount")
</div>

But when I run this project, _StatePartial method does not invoke and ViewBag always null.

Server Error in '/' Application.
Object reference not set to an instance of an object. 

Note that these parameters is not my model field and compute by calling a web service method. but I’m set these value in my question constantly.

What can I do for this?
Any idea for passing parameters to partial view?
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-06-14T14:33:06+00:00Added an answer on June 14, 2026 at 2:33 pm

    Your call:

    @Html.Partial("_StatePartial")
    

    will render the view, but it will not call the action. You would only use this if you were seeting up all your view data in your parent page action. In your case you need to use this:

    @Html.Action("_StatePartial")
    

    This will call the action first to retrieve and execute the view.

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

Sidebar

Related Questions

Here's the method i want to write: public static IEnumerable<String> GetTableNames(this IQueryable<T> query) {
I rendering a view partially like this. <%= render(:partial => index ,:controller=>controller_name) %> so
I've found a pattern in my Views like this: <% if (someCondition) { Response.Write(string.Format(Foo
I wrote the following method. public T GetByID(int id) { var dbcontext = DB;
Let's say I wrote a pretty simple class called ValueFinder that looks like this:
I wrote some script in a site. The script makes a new spreadsheet and
I wrote a Flickr search engine that makes a call to either a public
I'm learning about accessor methods and enumeration. I wrote a public class 'Car' under
why does this error occur.. The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some
I wrote a action filter which is similar to a log function : public

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.