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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:41:28+00:00 2026-05-15T23:41:28+00:00

In this line of code <% var tmp = int.Parse(ViewData[numOfGroups].ToString()); %> I have error:

  • 0

In this line of code

  <% var tmp = int.Parse(ViewData["numOfGroups"].ToString()); %>

I have error:Object reference not set to an instance of an object. How correctly convert

ViewData["numOfGroups"] to int?

  • 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-15T23:41:29+00:00Added an answer on May 15, 2026 at 11:41 pm

    You should first make sure that your controller action is setting this variable:

    public ActionResult Index()
    {
        ViewData["numOfGroups"] = "15";
        return View();
    }
    

    Once you’ve done this you should no longer get a NullReferenceException and your code should work.

    Of course as I’ve already written it multiple times here you should prefer strongly typed view instead of ViewData. Also you should type your model properties accordingly. It is not the responsibility of the view to parse strings. So:

    public ActionResult Index()
    {
        var model = new MyModel
        {
            NumOfGroups = 15
        };
        return View(model);
    }
    

    And in your view:

    <% var tmp = Model.NumOfGroups; %>
    

    By the way this should also be avoided as I have the feeling that you are declaring variables in your view which means that you have the intent of using them. Views are not for declaring variables and writing C# code. They are markup.

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

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As far as I know Matplotlib doesn't by design support… May 16, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer With your current setup, the Using statement is disposing of… May 16, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer Instead of using the JAXB RI (Metro), you could use… May 16, 2026 at 12:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

CSS: .divIm { border:1px solid red; } , and code-line var borderColor = $(this).css(border-color)
I am receiving this error: The ViewData item that has the key 'DepartmentId' is
I have the following classes (I've trimmed the code): public class SqlWeightTrackerRepository : IWeightTrackerRepository
I am using this code try document := (pDisp as IWebbrowser2).Document AS IHTMLDocument2; Body
The same line of code in the same assembly works for one test fixture
I am moving from jQuery to MooTools (for the fun..) and I have this
I have a livesearch and it uses an unordered list, like this: <input id=search/>
I have the following code in my page: <div id=data_body_container style=overflow: auto; width: 880px;
I have the following section of Razor code and it fails during runtime with
I'm trying to use python to parse a log file and match 4 pieces

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.