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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:29:54+00:00 2026-05-11T20:29:54+00:00

I am trying to validate a form using ModelState generally the same way as

  • 0

I am trying to validate a form using ModelState generally the same way as in tutorials on asp.net/mvc. However I dont have my own database or their objects and want to validate against Formcollection. I am not sure, how ModelState works, so maybe I am shooting in the dark, but here is the code, that crashes:

and NullReferenceException I get on the TextBox:

System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Mvc.HtmlHelper.GetModelStateValue(String key, Type destinationType) at System.Web.Mvc.Html.InputExtensions.InputHelper(HtmlHelper htmlHelper, InputType inputType, String name, Object value, Boolean useViewData, Boolean isChecked, Boolean setId, Boolean isExplicitValue, IDictionary2 htmlAttributes) at System.Web.Mvc.Html.InputExtensions.TextBox(HtmlHelper htmlHelper, String name, Object value, IDictionary2 htmlAttributes) at System.Web.Mvc.Html.InputExtensions.TextBox(HtmlHelper htmlHelper, String name, Object value) at ASP.views_authorized_account_aspx.__RenderContent1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\Trimack\Documents\Visual Studio 2008\Projects\GuestManager\AccountManager\Views\Authorized\Account.aspx:line 61*

Any ideas? Or am I completely wrong?

Trimack

  • 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-11T20:29:54+00:00Added an answer on May 11, 2026 at 8:29 pm

    So, for every error you add with ModelState.AddModelError() and call the View again, MVC Framework will try to find an AttemptedValue for every error it finds. Because you didn’t add them, MVC will throw an exception.

    http://forums.asp.net/p/1396019/3006051.aspx

    If there are errors then you must also set the model value as well as the modal error

    ModelState.AddModelError("Some_Key","Show some error message");
    ModelState.SetModelValue("Some_Key", ValueProvider["Some_Key"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I recommend you use a higher-level profiler. Here's a list:… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer StringHelpers could look like this: public class StringHelpers { private… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer The editor code comes from these JS files: http://www.stackoverflow.com/Content/Js/editor.js http://www.stackoverflow.com/Content/Js/wmd.js… May 11, 2026 at 11:45 pm

Related Questions

I am trying to send an email using c# using the following code. MailMessage
I'm trying to get into java again (it's been a few years). I never
I have a View with an exposed form . I am trying to a
I am trying to implement PayPal IPN functionality. The basic protocol is as such:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.