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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:12:04+00:00 2026-06-15T22:12:04+00:00

I have a few values that I’ve put in some hidden fields of a

  • 0

I have a few values that I’ve put in some hidden fields of a form using Razor. When I submit the form, it does not pass the validation that Entity Framework created in the context.tt model of a certain field. When I submit, there is an error thrown saying that the field cannot be null. This led me to believe that the value was null in the HTML. When I checked the source this is what i found:

<input Value="1" data-val="true" data-val-number="The field PoolType must be a number." id="PoolType" name="PoolType" type="hidden" value="" />
<input Value="Not Complete" id="LoanStatus" name="LoanStatus" type="hidden" value="" />
<input Value="2012-12-12 09:26.39" data-val="true" data-val-required="The DateStamp field is required." id="DateStamp" name="DateStamp" type="hidden" value="" />

I’m wondering why the input with id LoanStatus has a value set but it is throwing an error saying that it cannot be null. The exception thrown is:

System.Data.ConstraintException This property cannot be set to a null value.

To set the value in the HTML, I set it in the controller using the ViewBag, ViewBag.LoanStatus = "Not Complete";. Then in the cshtml file @Html.HiddenFor(model => model.LoanStatus, new { @Value = ViewBag.LoanStatus })

Is there something I am missing, I am new to MVC and Entity Framework.

EDIT – Additional Code
More hidden elements

@Html.HiddenFor(model => model.ID, new{ @Value = ViewBag.ID })
        @Html.HiddenFor(model => model.Reason, new{ @Value = ViewBag.Reason })
        @Html.HiddenFor(model => model.PoolType, new{ @Value = ViewBag.PoolType })
        @Html.HiddenFor(model => model.LoanStatus, new{ @Value = ViewBag.LoanStatus })
        @Html.HiddenFor(model => model.DateStamp, new{ @Value = ViewBag.DateTime })

And the html that is produced

<input Value="55" data-val="true" data-val-number="The field ID must be a number." data-val-required="The ID field is required." id="ID" name="ID" type="hidden" value="" />
        <input Value="1" data-val="true" data-val-number="The field Reason must be a number." id="Reason" name="Reason" type="hidden" value="" />
        <input Value="1" data-val="true" data-val-number="The field PoolType must be a number." id="PoolType" name="PoolType" type="hidden" value="" />
        <input Value="Not Complete" id="LoanStatus" name="LoanStatus" type="hidden" value="" />
        <input Value="2012-12-12 10:00.46" data-val="true" data-val-required="The DateStamp field is required." id="DateStamp" name="DateStamp" type="hidden" value="" />

EDIT Code without Html helper
Line from .cshtml file
<input type="hidden" name="LoanStatus" id="LoanStatus" data-val="true" value="@ViewBag.LoanStatus" />

Line from html source
<input type="hidden" name="LoanStatus" id="LoanStatus" data-val="true" value="Not Complete" />

  • 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-15T22:12:06+00:00Added an answer on June 15, 2026 at 10:12 pm

    When using @Html.HiddenFor the value for the input is read from your model object. You try to overwrite it by specifying a value for the Value attribute. I guess this won’t work and as you see, you get empty value attributes.

    To solve your problem, don’t use the viewbag but pass a model object with the values set to your view like this:

    Controller:

    return View(new YourModel { LoanStatus = "Not Complete" });
    

    View:

    @Html.HiddenFor(m => m.LoanStatus)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few input fields in a form which are submitted using Save
In a multiplayer game I'm developing, we have a few values that are floating
I have a few data values that I need to store on my rails
I have few fields and I want the values inside those fields to get
I have a few values in a function, which get in that function, that
I have a login page that stores a few values to localStorage (html5) then
I have a few radio buttons that I'm styling with PNG background images, using
I have few values that are DB driven/or coming from other system which i
I have a HTML page that displays a few values. I also have a
I have a graph that auto fills based on a few values. The values

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.