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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:32:00+00:00 2026-05-25T12:32:00+00:00

I was having a weird issue with a very simple model. When posted back

  • 0

I was having a weird issue with a very simple model. When posted back to the controller, the model was always null. Not being able to find the issue, I pulled it apart rebuilt the model, adding an accessor at a time.

I finally discovered that having a string accessor called “State” and using it in a view was causing the issue:

<%= Html.HiddenFor(m => m.State) %>

Why would this happen?

Here is the model:

public class StudentSelectState
{
    public string State { get; set; }
    public int SelectedYear { get; set; }
    public IDictionary<string, string> Years { get; set; }
}

Here is the controller:

    [HttpGet]
    public ActionResult SelectStudent()
    {
        var StudentYears = absenceServices.GetStudentYears();
        var state = new StudentSelectState {Years = Lists.StudentYearListToDictionary(StudentYears)};

        return View(state);
    }

    [HttpPost]
    public ActionResult SelectStudent(StudentSelectState state)
    {
        var StudentYears = absenceServices.GetStudentYears();

        state.Years = Lists.StudentYearListToDictionary(StudentYears);

        return View(state);
    }

and here is the view:

<% using (Html.BeginForm())
    {%>
    <%= Html.ValidationSummary() %>
        <%= Html.TextBoxFor(m => m.State) %>
        <%= Html.RadioButtonListFor(m => m.SelectedYear, Model.Years, "StudentYears") %>
    <div style="clear: both;">
        <input value="submit" />
    </div>
<% } %>

The RadioButtonListFor is a HtmlHelper I wrote to populate RadioButtonLists.

I am using Ninject 2.0 to inject services into the contructor, but I don’t think this has a bearing on this issue.

I could rename the accessor, but I’m curious as to why this is happening.

  • 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-25T12:32:01+00:00Added an answer on May 25, 2026 at 12:32 pm

    You could also rename the argument of your POST action.

    [HttpPost]
    public ActionResult SelectStudent(StudentSelectState model)
    

    When you POST the form the following is sent in the request:

    State=abcd
    

    Now the default model binder sees that your action argument is called state and it tries to bind the abcd value to it which obviously fails because the state variable is not a string. So be careful when naming your view model properties.

    To avoid those kind of conflicts I prefer to name my action arguments model or viewModel.

    Yet another possibility if you don’t want to rename anything is to use the [BindPrefix] attribute, like so:

    [HttpPost]
    public ActionResult SelectStudent([Bind(Prefix="")]StudentSelectState state)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a very weird issue with templates. Getting an error error: ‘traits’
I'm having a very weird issue with the command line and running Ant. I
I am having a very weird issue in the way strings get stored in
I'm having a very weird issue in IE6. If I set a div container
Im having a very weird issue. I have a normal ajax call that upload
I'm having a weird issue with a button that is being shown on screen,
I'm having a weird issue with Visual Studio 2008. Every time I fire it
PROBLEM SOLVED: I was overlooking a very simple issue, and that is that this
I'm getting a very weird issue with standard ASP.NET backend code, and the latest
I'm currently having a really weird issue and I can't seem to figure out

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.