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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:35:29+00:00 2026-06-14T09:35:29+00:00

[HttpPost] public ActionResult Create(Users user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return RedirectToAction(Index); }

  • 0
[HttpPost]
public ActionResult Create(Users user)
{
    if (ModelState.IsValid)
    {
        db.Users.Add(user);
        db.SaveChanges();
        return RedirectToAction("Index");  
    }

    return View(user);
}

ModelState.IsValid is always false.
so it just return view and new record is not getting added..

Edit

User:

public class User
{
    public int UserID { get; set; } 
    public string Name { get; set; } 
    [Display(Name = "Confirm Password")] [DataType(DataType.Password)] 
    public string ConfirmPassword { get; set; } 
    public string Designation { get; set; } 
    [Display(Name = "Date of Join")] [DataType(DataType.Date)] public DateTime DOJ { get; set; } 
    public string Email { get; set; } 
    [Display(Name = "Phone Number")] public System.Int64 PhoneNo { get; set; }
}
  • 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-14T09:35:30+00:00Added an answer on June 14, 2026 at 9:35 am

    ModelState.IsValid will be false if the validation for the Model failed.

    1. You have DataAnnotation which failed the incoming model.
    2. You added custom validations.
    3. Make sure there are no null entries in the model for non null properties

    Check the ModelState.Errors for what is the reason causing this. You can use this:

    var errors = ModelState.Values.SelectMany(v => v.Errors);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works: [HttpPost] public ActionResult Slots(Slots slots, ICollection<int> jobNos) { if (!ModelState.IsValid) return View(new
With ASP.net MVC I'm doing this: [HttpPost] [TransactionFilter] public ActionResult Create(User user) { //
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
i have 2 actions public ActionResult FilesAdd(int id) { FillParentMenuDDL(id); return View(); } [HttpPost]
In my controller, I always end up with something like: [HttpPost] public ActionResult General(GeneralSettingsInfo
Is it possible to have a ActionResult with a signature of: [HttpPost] public ActionResult
This is a code fragment from my controller [HttpPost] public ActionResult Cancel(string id,FormCollection collection)
The controller ... [HttpPost] public virtual ActionResult PickAColour(ColourModel model, string imgbtn, string returnUrl) {
This is what my controller action looks like [HttpPost] [OutputCache(Location = OutputCacheLocation.None)] public ActionResult
is it allowed in ASP.NET MVC to alter the submitted values? [HttpPost] public ActionResult

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.