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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:27:50+00:00 2026-05-22T19:27:50+00:00

[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude = Id)]CustomerInfo customerinfo) { if (customerinfo.FirstName.Trim().Length == 0) ModelState.AddModelError(FirstName, First

  • 0
[AcceptVerbs(HttpVerbs.Post)]   
public ActionResult Create([Bind(Exclude = "Id")]CustomerInfo customerinfo)

{

   if (customerinfo.FirstName.Trim().Length == 0)
       ModelState.AddModelError("FirstName", "First name is required.");
   if (customerinfo.LastName.Trim().Length == 0)
       ModelState.AddModelError("LastName", "Last name is required.");
   if (customerinfo.Phone.Length > 0 && !Regex.IsMatch(customerinfo.Phone, @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"))
       ModelState.AddModelError("Phone", "Invalid phone number.");
   if (customerinfo.Email.Length > 0 && !Regex.IsMatch(customerinfo.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
       ModelState.AddModelError("Email", "Invalid email address.");
   if (!ModelState.IsValid)
       return View();
   try
   {
        BLL.Customer customer = new BLL.Customer();
        customer.CreateCustomer(customerinfo);

        return RedirectToAction("Index");

    }
    catch
    {
        return View();
    }
}
  • 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-22T19:27:51+00:00Added an answer on May 22, 2026 at 7:27 pm

    You should really step through and indicate where exactly it fails. Most likely this would tell you enough to fix the problem yourself. In particular, look at the line-number; that will take you to the line that is failing.

    However, my guess is simply that one of FirstName, LastName, Phone or Email is null (which is the default for strings, so entirely expected) – or that customerinfo itself is null.

    Changing to

    if (customerinfo.FirstName == null || customerinfo.FirstName.Trim().Length == 0)
       ModelState.AddModelError("FirstName", "First name is required.");
    

    (etc) will probably fix it for you.

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

Sidebar

Related Questions

My controller calls a repository class method on insert, [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude =
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude = Id)] ContentPageNav contentToCreate) { DataClasses1DataContext dc = new DataClasses1DataContext();
I've got a controller action like this: [ActionName(Create), AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Exclude=Id)]Project project) {
[AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateUser([Bind(Exclude = Id)] User user) { ... db.SubmitChanges(); ViewData[info] = The
I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection)
I have some code like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Prefix=)]Person person) { String s
I can decorate an action either with the [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string title)
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(Photo photo) { foreach (string file in Request.Files) { var path
I have a controller method with the following signature: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateValues(int id,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.