How to limit the number of customers entered Asp.net MVC

user8869595

I'm trying to create a code where when the user enters five customers into the gridview it gives them an error saying that they should only enter 5 customers; what is happening now is that the user can any amount of customers. I added the error line but it seems I put it the wrong place because the user is still able to add more than 5.

for (int i = 0; i < getCustomer.items.Count; i++)
{
    if (getIssue.name[i].idNumber == Customer.name.idNumber)
    {
        ViewBag.errorMessage = "ID number already exists";
        return View(getCustomer);
    }

    if (getCustomer.items.Count >5)
    {
        viewBag.errorMessage=Error, You can only enter 5 customers at a time;
    }

}

if (name.Count == 0)
{
    nametbl.connectionString = ConfigurationManager.ConnectionStrings["CUSTOMERConnectionString"].ConnectionString;
    try
    {
        name = nametbl.getName();
    }
    catch (Exception ex)
    {
        LogWrite logWriter = new LogWrite(ex.ToString());
        ViewBag.errorMessage = "Unable to Connect to Database. Please see Log file for more Information";
        return View(getCustomer);
    }
}
zaitsman

You just need to return from command flow like so:

   if (getCustomer.items.Count >5)
    {
        viewBag.errorMessage=Error, You can only enter 5 customers at a time; // <=== AFTER THIS LINE
        return View(getCustomer);
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to allow only positive number to be entered in editorforfield in asp.net mvc 5

How can I limit the number times of each user have permission to try login in ASP.NET MVC

How to retrieve the total number of customers (without a "limit") with the stripe API

How to limit the number of characters in MVC

How to count the number of records in the model with ASP.NET MVC?

Can't get values ​entered in ASP.NET MVC Form

How to limit the number of records saved in a day in ASP.Net Web Forms?

Search By Number in ASP.NET MVC

Limit number of lines entered in WPF textbox

ASP>NET Identity: How to compare a password entered by the user with a hashed password?

How to make asp .net to forget entered text in fields?

Trying to restrict size limit for int datatype in ASP.NET MVC

ASP.NET Identity Phone Number Token lifespan and SMS limit

How to get the Number of ApplicationUser in the AspNetUsers Table in ASP.Net MVC 5?

How to retrieve the count of the number of rows in asp.net mvc from sql database?

how to show number of users by age group in chart control in Asp.net MVC

ASP.Net Core MVC how to post unknown number of fields against strongly-typed model

How to confirm a phone number in ASP.Net Core 1.1MVC

How do I get the List of Role and Number of users in them asp.net mvc

How to display the number of all checkboxes that have been checked in Table, asp.net MVC Razor

asp.net mvc 5 how to set number into long value like 101-2esdf-1212

ASP.NET MS11-100: how can I change the limit on the maximum number of posted form values?

How ensure that a number is entered on the console

how not to allow a negative number to be entered in for

Setting number value in JavaScript via Razor in ASP.NET MVC

count number of row in table asp.net mvc

ASP.NET Core MVC table keeps showing same number

Trying to post a serialized form and number to controller in ASP.NET / MVC

How to implement Localization ASP net CORE MVC