1
I’m trying to use a input
with type=number
, but in Chrome is giving that the value informed should be a number.
The problem is the state model that is returning invalid, because when giving the post, is entering Create.
I’ve implemented the globalize as in reply, but did not solve the case.
My view
@model WebApplication24.Models.Produto
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Produto</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Descricao, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Descricao, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Descricao, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Valor, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Valor, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any" } })
@Html.ValidationMessageFor(model => model.Valor, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Quantidade, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Quantidade, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any" } })
@Html.ValidationMessageFor(model => model.Quantidade, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ValorCusto, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ValorCusto, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any" } })
@Html.ValidationMessageFor(model => model.ValorCusto, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
</script>
}
My bill
var bundle = new ScriptBundle("~/bundles/jqueryval") { Orderer = new AsIsBundleOrderer() };
bundle
.Include("~/Scripts/jquery.validate.js")
.Include("~/Scripts/jquery.validate.unobtrusive.js")
.Include("~/Scripts/globalize.js")
.Include("~/Scripts/jquery.validate.globalize.js")
.Include("~/Scripts/methods_pt.js");
bundles.Add(bundle);
methods_pt
jQuery.extend(jQuery.validator.methods, {
number: function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
}
});
Installed packages
Microsoft.AspNet.Mvc.en version="5.2.3"
jQuery.Validation.Globalize version="1.1.0"
jquery-globalize" version="1.1.1"
--
I edited the code of the view performing the suggestions of Márcio, but still continues saying that the value informed is not valid
I added the example codes to my Github
is already that way my web.config
– Pablo Tondolo de Vargas
In your model, the fields are Double?
– Douglas Fernandes
They are decimal, I posted in the question the link to download the project
– Pablo Tondolo de Vargas
@Pablovargas, I looked at the project and found no problem. I think then you’ll need to implement Binder, and add it to Global.asax, follows an example link: http://www.devmedia.com.br/asp-net-mvc-manipulando-monetaryvalues/28907
– Douglas Fernandes