Note that there are some explanatory texts on larger screens.

plurals
  1. PORange validation for textbox not working in MVC3
    text
    copied!<p>I am trying to raise validation error in an ASP.Net MVC 3 application. When the user enters a number that is greater than 1000 an error message should be displayed. with the following code on a view model it doesn't seem to be working.<br> What do i need to change?</p> <pre><code>[Range(0, 1000, ErrorMessage = "Total number of rows to display must be between 0 to 1000")] public int DisplayTop { get; set; } </code></pre> <p>cshtml :</p> <pre><code>@model Calc.Models.CountingVM @{ ViewBag.Title = "Reports"; Layout = "~/Views/Shared/_reportsLayout.cshtml"; } @using (Html.BeginForm("Reports", "Calc", FormMethod.Post, new { @id = "frmReport" })) { ......... @Html.TextBoxFor(c =&gt; c.DisplayTop, "1000") @Html.ValidationMessageFor(c =&gt; c.DisplayTop) } </code></pre> <p>Action Method :</p> <pre><code> public ActionResult Reports(string ReportName, CalcCriteria criteria) { if ((criteria == null) || (criteria.nId == null)) { criteria = TempData["criteria"] as CalcCriteria; TempData["criteria"] = criteria; // For reload, without this reloading the page causes null criteria. } ReportType c = (ReportType)Enum.Parse(typeof(ReportType), ReportName, true); JavaScriptSerializer serializer = new JavaScriptSerializer(); string vmJson = string.Empty; switch (c) { ..... int displayTop; .......... case ReportType.Inventory_Counts_Report: .............. displayTop = Convert.ToInt32(Request["DisplayTop"]); ........ return View("Counting", CountingVM); default: return View(); } return View(); } </code></pre> <p>Thanks </p> <p>BB</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload