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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:24:22+00:00 2026-05-25T17:24:22+00:00

I Got an error While submit Object reference not set to an instance of

  • 0

I Got an error While submit “Object reference not set to an instance of an object” mvc2

View page

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EventListing.Models.EventInfo>" %>
<%= Html.DropDownListFor(model =>  model.SelectedTimeZone, Model.TimeZones, "Select Timezone") %>

Controller

 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(EventInfo EventInfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EventModel.Create(EventInfo);
                    return RedirectToAction("Index");
                }
                return View(); 
            }
            catch
            {
                return View();
            }
        }

Model

public SelectList TimeZones { get; set; }
private string selectedTimeZone = "";
        public string SelectedTimeZone
        {
            get { return selectedTimeZone; }
            set { selectedTimeZone = value; }
        }

public static IList<KeyValuePair<string, string>> getTIMEZOMES
        {
            get
            {
                Dbhelper DbHelper = new Dbhelper();
                IList<KeyValuePair<String, String>> Timezone = new List<KeyValuePair<String, String>>();
                DbCommand cmd = DbHelper.GetSqlStringCommond("SELECT * FROM TMP_TIMEZONES");
                DbDataReader Datareader = DbHelper.ExecuteReader(cmd);
                while (Datareader.Read())
                {
                    Timezone.Add(new KeyValuePair<String, String>(Datareader["ABBR"].ToString(), Datareader["NAME"].ToString()));
                }

                return Timezone;
            }
        }

Plz give me the solution.

  • 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-25T17:24:22+00:00Added an answer on May 25, 2026 at 5:24 pm

    You need to repopulate the data for the dropdown in the [HttpPost] parts of the Create action just like I’m guessing you are doing in the GET version of your Create action. When you do a return View(Model) in the HttpPost action it literally returns that HTML view and it needs all the supporting data too just like in the GET!

     [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult Create(EventInfo EventInfo)
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        EventModel.Create(EventInfo);
                        return RedirectToAction("Index");
                    }
                    // MISSING model in below call plus likely viewdata/viewbag for dropdownlist
                    // why are you returning same view as returned when error? normally this is a RedirectToAction("DisplayEvent") or similar!
                    return View(EventInfo); 
                }
                catch
                {
                    // MISSING model in below call plus likely viewdata/viewbag for dropdownlist
                    return View(EventInfo);
                }
            }
    

    So at least two errors:

    1. When save succeeds why are you returning same view as if save fails?
    2. When save fails, need to pass in the EventInfo to the view (and populate viewdata/viewbag if needed for DropDownList)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got an error while trying to invoke the webservice System.NullReferenceException: Object reference not set
I've got an error while updating WCF service reference in Visual Studio 2010: There
I got an error today while trying to do some formatting to existing code.
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
While working on an existing project I suddenly got the following error when trying
I got RJS error: TypeError: element is null while using ajax. I used in
Opencv Error: I got the following error while installing OpenCV on Lucid. 81% ....
I got this error while trying to compile the below code. I would like
sir i have got an error while running my project in ecclipse. The error
I need help on this. I got this error while inserting/updating a number of

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.