none
Problema al insertar numero con parte decimal en Db ? RRS feed

  • Pregunta

  • Hola

    Tengo una aplicacion donde creo factura (Mvc , Code First y Entity Framework) , En el campo Total cuando ingreso un numero entero funciona perfectamente, si intento ingresar por ejemplo (12.45) en la tabla se inserta (0) y si intento(12,45) me sale un mensaje que el campo espera un numero...

    Como puedo resolver esto ?

    Mi clase Factura

    namespace MvcTutorialPractice.Models.DbTable
    {
        [Table("Factura")]
        public class Factura
        {
            public int Id { get; set; }
    
            [Column(TypeName = "VARCHAR")]
            [StringLength(20)]
            [Required]
            public string Numero { get; set; }
    
            [Column(TypeName = "VARCHAR")]
            [StringLength(500)]
            [Required]
            public string RazonSocial { get; set; }
    
            [Column(TypeName = "VARCHAR")]
            [StringLength(50)]
            [Required]
            public string Rif { get; set; }
    
            [Required]
            public DateTime Fecha { get; set; }
    
            [Required]
            public double Total { get; set; }
    
        }
    }

    Diseño de la Tabla

    La vista Factura

    @model MvcTutorialPractice.Models.DbTable.Factura
    
    @{
        ViewBag.Title = "Factura";
    }
    
    <h2>Factura</h2>
    
    
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()
        
        <div class="form-horizontal">
            <h4>Factura</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.Numero, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Numero, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Numero, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.RazonSocial, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.RazonSocial, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.RazonSocial, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Rif, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Rif, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Rif, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Fecha, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Total, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Total, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Total, "", 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" />
                    <input type="reset" value="Cancel" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    
    <div>
        @Html.ActionLink("Back to List", "Index")
    </div>
    
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    


    EFRAIN MEJIAS C VALENCIA - VENEZUELA

    domingo, 10 de febrero de 2019 20:27

Respuestas