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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:53:18+00:00 2026-06-13T05:53:18+00:00

I use an update action to update based on the input from the @Html.Textbox.

  • 0

I use an update action to update based on the input from the @Html.Textbox.

@using (Html.BeginForm("Update", "Shopping", new { UserID = Request.QueryString["UserID"] }, FormMethod.Post, new { id = "myForm" }))
   {               
   @Html.ValidationSummary()                
   @Html.Hidden("id", @Request.QueryString["UserID"] as string)
   @Html.Hidden("productid", item.ProductID as string)
   @Html.TextBox("Quantity", item.Quantity)   
   @Html.ValidationMessage("Quantity", "*") 
   @Html.Hidden("unitrate", item.Rate)               
   <input type="submit" value="Update" />
   }

and In My Model class

        [Required(ErrorMessage = "Quantity is required.")]
        [Display(Name = "Quantity")]
        [Range(2, 100, ErrorMessage = "There is not enough inventory for the product to fulfill your order.")]
        public int? Quantity { get; set; }

The problem is I m not getting the validation message when the textbox is empty.
But when I use @Html.TextBoxFor

   @Html.TextBoxFor(modelItem => item.Quantity)
   @Html.ValidationMessageFor(modelitem => item.Quantity) 

I am getting the validation message. and my update action is not working.

Here I have two options.

1. How to pass the textbox name “qty” in @Html.TextboxFor ?? (or)

2. How to get the validation message in @Html.Textbox() using @Html.ValidationMessage()

Any suggestions ..

EDIT :
My Update Action

[HttpPost]
   public ActionResult Update(string id, string productid, int Quantity, decimal unitrate)
        {
        if (ModelState.IsValid)
         {
                   int _records = UpdatePrice(id, productid, Quantity, unitrate);
                    if (_records > 0)
                    {
                        return RedirectToAction("Index1", "Shopping", new { UserID = Request.QueryString["UserID"] });
                    }
                    else
                    {
                        ModelState.AddModelError("","Can Not Update");
                    }
                }
                return View("Index1");
            }
  • 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-13T05:53:19+00:00Added an answer on June 13, 2026 at 5:53 am

    you have the answer in your question, when you use

    @Html.TextBoxFor(modelItem => item.Quantity)
    @Html.ValidationMessageFor(modelitem => item.Quantity)
    

    you get the error message becasue the MVC model validation works on the name attributes as @Mystere Man said in the comments you are defying all the conventions and conventions is what MVC is all about, either change the property name in your model or use it as it is in the view if you want to leverage the MVC’s model validation.


    Not entirely relevant but a good read.

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

Sidebar

Related Questions

I need to use scp update some directory at another server. It is similar
I am trying to use an update query to update the first 3 characters
I am trying to use an update trigger in SQL Server 2000 so that
I periodically receive data that I use to update my database with. The external
I have a form view which people use to update a record in the
I have a web page that I use to update a fairly complex data
Quoting MySQL INSERT manual - same goes for UPDATE: Use the keyword DEFAULT to
I use EGORefreshTableHeaderView to update my tableview. Here I call my method to download
I would like to use jquery to update my attribute value, because I want
How can I use automapper to update the properties values of another object without

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.