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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:40:29+00:00 2026-06-11T10:40:29+00:00

I am having trouble with the following error message: Object reference not set to

  • 0

I am having trouble with the following error message:

Object reference not set to an instance of an object.

break on lines:

Line 16:         </div>
Line 17:         <div class="editor-field">
Line 18:              @Html.DropDownList("KPI.CSF.FYID", Model.Financial_Years)
Line 19:             @Html.ValidationMessageFor(model => model.KPI.CSF.FYID)
Line 20:         </div>

This occurs during form post in my mvc project.

I am passing a viewmodel of the following when I load the create form:

public class KPICreateFormViewModel
    {

        //Properties
        public KPI KPI { get; set; }
        public SelectList Financial_Years { get; private set; }

        FYRepository fyrepo = new FYRepository();
      public KPICreateFormViewModel(KPI kpi)
        {
            KPI = kpi;
            Financial_Years = new SelectList(fyrepo.GetFys(), "ID", "Financial_Year");

        }

    }

I use the financial years for a dropdown which then initiates some ajax to cascade some other dropdowns which will populate ID numbers in my post.

I do not want my financial years dropdown to post anything back during the http post method of my controller.. so I figured if I just pass back the following I would be ok:

[HttpPost]
    public ActionResult Create(KPI kpi)
    {
        try
        {

            kpirepository.Add(kpi);
            kpirepository.Save();


            return RedirectToAction("Details", new { id = kpi.ID });
        }
        catch
        {
            return View();
        }
    }

I assume this is all happening because of my view being based on the viewmodel and then on post I am not handing this back? After hours of messing with the cascade code to get it working my head is a bit fried to try and tackle this issue.. help!

The relevant part for my view showing the financial year dropdown:

@model ES_Business_Intelligence.ViewModels.Admin.KPICreateFormViewModel

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>KPI</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.KPI.CSF.FYID)
        </div>
        <div class="editor-field">
             @Html.DropDownList("KPI.CSF.FYID", Model.Financial_Years)
            @Html.ValidationMessageFor(model => model.KPI.CSF.FYID)
        </div>
  • 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-11T10:40:30+00:00Added an answer on June 11, 2026 at 10:40 am

    After confirmation of the problem from webdeveloper I did some more digging and found I can tell certain elements of my viewmodel to not bind when returning data from my form submit. I added the following code to my viewmodel:

    [Bind(Exclude = "Financial_Years")]
        public class KPICreateFormViewModel
        {
    
            //Properties
            public KPI KPI { get; set; }
            public SelectList Financial_Years { get; private set; }
    
            FYRepository fyrepo = new FYRepository();
          public KPICreateFormViewModel(KPI kpi)
            {
                KPI = kpi;
                Financial_Years = new SelectList(fyrepo.GetFys(), "ID", "Financial_Year");
    
            }
    
        }
    

    The magic is all in the first line:

    [Bind(Exclude = "Financial_Years")]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having trouble getting my directx going I get the following error 1>Linking... 1>main.obj :
Having trouble creating my swap chain. I receive the following error. DX3dApp.obj : error
I am having trouble finding why the following XML won't deserialize. Message: There is
I'm having compile time trouble with the following code: template <typename T, template <class
I am having trouble mocking an injected object. For example: class Foo def initialize(bar
I'm having trouble following this guide to extract my interfaces and entities from my
I am having trouble following the AngelScript manual on the proper way to register
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm having trouble with the following scenario: 2 Edit's Type something in Edit1 and
I am having trouble with the following MYSQL query and are hoping that there

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.