Ramco Ramco

Ramco Ramco

  • 469
  • 2.8k
  • 388.9k

Validation Error not Displayed

Jun 15 2021 6:16 AM

Hi

        public Location()
        {
        }

        [Key]
        [Required]
        [RegularExpression(@"^[a-zA-Z'.\s]{1,4}$", ErrorMessage = "Special Characters not allowed")]
        [Display(Name = "Id")]
        public string Id { get; set; }

        [DataType(DataType.Text)]
        [RegularExpression(@"^[a-zA-Z'.\s]{1,25}$", ErrorMessage = "Special Characters not allowed")]
        [Required(ErrorMessage = "Please enter Location"), MaxLength(25)]
        [Display(Name = "Description")]
        public string Description { get; set; }

    }

********************************************************************************

@model MyApplication.Models.Location

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>CreateEdit</title>
</head>
<body>

    @using (Html.BeginForm("CreateEdit", "Location", FormMethod.Post, new { @id = "locationFormId", @class = "form-horizontal", role = "form" }))
    {
        @Html.AntiForgeryToken()

        <div class="" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
                        <h4 Create New Location></h4>
                    </div>
                    <div class="modal-body">

                        @*<div class="form-horizontal">
                            <h4>Location</h4>
                            <hr />*@
                            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                            @Html.HiddenFor(model => model.Id)

                            <div class="form-group">
                                @Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
                                <div class="col-md-10">
                                    @Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
                                <div class="col-md-10">
                                    @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                                </div>
                            </div>

                            @*<div class="form-group">
                                    @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" })
                                    <div class="col-md-10">
                                        <div class="checkbox">
                                            @Html.EditorFor(model => model.IsActive)
                                            @Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>*@

                            @*<div class="form-group">
                                <div class="col-md-offset-2 col-md-10">
                                    <input type="submit" value="Save" class="btn btn-default" />
                                </div>
                            </div>*@
                        @*</div>*@
                    </div>
                    @*@Html.ActionLink()*@
                    <div class="modal-footer">
                        @Html.ActionLink("Cancel", "Index")

                        <button type="submit" class="btn btn-primary">Save Changes</button>
                    </div>
                </div>
            </div>
            </div>
            }

</body>
</html>

Thanks


Answers (2)