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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:31:47+00:00 2026-06-17T20:31:47+00:00

Very basic Model: public class Person { public string Name; public int Age; }

  • 0

Very basic Model:

public class Person
{
    public string Name;
    public int Age;
}

and very simple view:

@model DynWebPOC.Models.Person

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

Hello, @Model.Name
<br/>
You're getting old at @Model.Age years old now!

@using(Html.BeginForm("Index","Test",FormMethod.Post))
{
    <fieldset>       
        <label for="name" style="color: whitesmoke">Name:</label>    
        @Html.TextBoxFor(m => m.Name)
        <br/>
        <label for="age" style="color: whitesmoke">Age:</label>

        @Html.TextBoxFor(m => m.Age)

        <br/>
        <input type="submit" value="Submit"/>
    </fieldset>
}

And a very simple controller:

public class TestController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        object model = new Person {Name = "foo", Age = 44};
        return View(model);
    }


   [HttpPost]
   public ActionResult Index(Person person)
   {
       return View();
   }
}

When the screen loads, the values bind correctly to the page. But when I push submit button, the person object has all null values for age & name.

Because I used Html.TextBoxFor, shouldn’t it have set up all the bindings correctly and the object should have automatically bound back to the POST? It binds just fine in the GET..

Did I miss something in the call to Html.BeginForm() maybe?

  • 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-17T20:31:48+00:00Added an answer on June 17, 2026 at 8:31 pm

    You must create Properties in your model

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
    

    instead of

    public class Person
    {
        public string Name;
        public int Age;
    }
    

    ASP.net MVC only binds properties.

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

Sidebar

Related Questions

Let me have two very basic objects like: public class View { public View(Controller
I have very basic category model ID, RootCategoryID, Name and if I have category
I have a basic MVC view model with annotations, for example: [Required(ErrorMessage=Your Name Required)]
Assume i have this model public partial class Todo { public int id {
I have a very basic Admin model: class Admin < ActiveRecord::Base has_secure_password validates_uniqueness_of :email
I have a very basic model - User I am trying to do some
I have implemented a very basic sign up using email address+name, although I would
This is my custom model binder code for the BaseContentObject class: public class BaseContentObjectCommonPropertiesBinder
I'm trying to add my custom view and controller to a VERY basic roo-generated
I have a very basic entity model which I'm trying to add custom validation

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.