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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:22:07+00:00 2026-06-16T13:22:07+00:00

I am using Visual Studio 2010 and mvc 2.0. In my controler, i have

  • 0

I am using Visual Studio 2010 and mvc 2.0.

In my controler, i have a ViewResult which is picking data from a view page customerDataAdd. there are 8 fields(textbox). I have a model just with get{ } and set{ } of this 8 field.

The problem is, in action of the submit button, it goes to ViewResult, create an object of the model.Customer, tries to insert data from the view to the models property and fail.

The error is: Object reference not set to an instance of an object.

Here is some of my code given below:

Customer.cs- model class

    private string _FirstName;
    public string FirstName
    {
      get { return _FirstName; }
      set { _FirstName = value; }
    }

    private string _LastName;
    public string LastName
    {......}

    private string _Street;
    public string Street
    {......}

    private string _Village;
    public string Village
    {......}

    private string _Thana;
    public string Thana
    {......}

    private string _District;
    public string District
    {......}

    private string _Division;
    public string Division
    {......}

    private string _Country;
    public string Country
    {......}

CustomerController.cs -> ViewResul DisplayCustomer() –> where the error shows is in second line.

[HttpPost]
    public ViewResult DisplayCustomer()
    {
        Models.Customer customerView = new Models.Customer();   //all customerview properties are null??
        **customerView.FirstName = Request.Form["atxtFirstName"].ToString();** //firstname gets null??
        customerView.LastName = Request.Form["atxtLastName"].ToString();
        customerView.Street = Request.Form["atxtStreet"].ToString();
        customerView.Village = Request.Form["atxtVillage"].ToString();
        customerView.Thana = Request.Form["atxtThana"].ToString();
        customerView.District = Request.Form["atxtDistrict"].ToString();
        customerView.Division = Request.Form["atxtDivision"].ToString();
        customerView.Country = Request.Form["atxtCountry"].ToString();

        return View();
    }

[edit-1]
value of my form[“atxtFirstName”].ToString() = null showing. I have edited it with FormCollection as said.

[edit-2]

Here is my DisplayCustomer.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SimpleExample.Models.Customer>" %>

DisplayCustomer

<h2>DisplayCustomer</h2>
<div>
    <table runat="server" width="30%">
        <tr>
            <td width="30%">Customer Name: </td>
            <td><%= Model.FirstName + " " + Model.LastName %></td>
        </tr>
        <tr>
            <td>Customer Address: </td>
            <td><%= Model.Street + ", " + Model.Village + ", " + Model.Thana + ", <br/>" + Model.District + ", " + Model.Division + ", " + Model.Country %></td>
        </tr>
    </table>
</div>

My CustomerDataAdd.aspx – just the form is given here.

<form id="afrmCustomer" runat="server" action="DisplayCustomer" method="post">
    <table width="30%">
        <tr>
            <td width="30%">
                <asp:Label ID="Label8" Text="First Name:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtFirstName" runat="server" />
            </td>
            <td width="30%">
                <asp:Label ID="Label1" Text="Last Name:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtLastName" runat="server" />
            </td>
        </tr>
        <tr>
            <td width="30%">
                <asp:Label ID="Label2" Text="Street:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtStreet" runat="server" />
            </td>
            <td width="30%">
                <asp:Label ID="Label7" Text="Village:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtVillage" runat="server" />
            </td>
        </tr>
        <tr>
            <td width="30%">
                <asp:Label ID="Label3" Text="Thana / Upazilla:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtThana" runat="server" />
            </td>
            <td width="30%">
                <asp:Label ID="Label6" Text="District:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtDistrict" runat="server" />
            </td>
        </tr>
        <tr>
            <td width="30%">
                <asp:Label ID="Label4" Text="Division:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtDivision" runat="server" />
            </td>
            <td width="30%">
                <asp:Label ID="Label5" Text="Country:" runat="server" />
            </td>
            <td>
                <asp:TextBox name="atxtCountry" runat="server" />
            </td>
        </tr>
        <tr>
            <td width="30%">
            </td>
            <td>
                <asp:Button name="abtnSubmit" Text="Submit" runat="server" />
            </td>
            <td width="30%">
            </td>
            <td>
            </td>
        </tr>
    </table>
    </form>
  • 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-16T13:22:08+00:00Added an answer on June 16, 2026 at 1:22 pm

    I got the point. as i am using server control this process is not the correct one for passing value from server control. I just have to use html. But i don’t know why this is. Please if anyone can answer, i will be grateful.

    i used:

    <input type="text" name="atxtFirstName" />
    

    and this works for all!

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

Sidebar

Related Questions

i am using visual studio 2010. i have a three dimensional structure array which,
I am using Visual Studio 2010 for an MVC website project. I have an
I am using Visual Studio 2010 / ASP.net MVC 3 with the Razor View
We have developers using Visual Studio 2010 professional and some trying out Visual Studio
I am using Visual Studio 2010. I've donwloaded an updated class (i.e. UpdatedClass.cs) which
I am developing an MVC3 application using Visual Studio 2010. I have an aspx
I'm going to be building some ASP.Net MVC 2 software using Visual Studio 2010
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a
Using Visual Studio 2010, MVC project When my form is submitted (currently via javascript,
Setup: I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power

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.