Base solution for your next web application
Open Closed

Non Modal page with standard Asp.net core validation #8805


User avatar
0
mhdevelop created

Hello, I want to use non modal page with standard asp.net core validations. When I run this code I get validation error insted of screen updating with error message. I have gone through how to convert model page to standard, but not able to figure out. This is very important in situation where we have complex UI to build and not seen any samples. Here is simple example to create a category.

<div id="details" style="height:100%"> @using (Html.BeginForm()) { @Html.AntiForgeryToken()

    &lt;div class=&quot;form-horizontal&quot;&gt;
        &lt;h4&gt; Category &lt;/h4&gt;
        &lt;hr /&gt;
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.CategoryId)

        &lt;div class=&quot;form-group&quot;&gt;
            @Html.LabelFor(model => model.CategoryName, htmlAttributes: new { @class = "control-label col-md-2" })
            &lt;div class=&quot;col-md-10&quot;&gt;
                @Html.EditorFor(model => model.CategoryName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CategoryName, "", new { @class = "text-danger" })
            &lt;/div&gt;
        &lt;/div&gt;

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

        &lt;div class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
                &lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-default&quot; /&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
}

&lt;div&gt;
    @Html.ActionLink("Back to List", "Index")
&lt;/div&gt;

</div>

The Category Class [Key] [Column("CategoryID")] public int CategoryId { get; set; }

    [Required]
    [StringLength(15)]
    public string CategoryName { get; set; }
    
    [Column(TypeName = "ntext")]
    public string Description { get; set; }

Thanks for any help with example insted of pointing to standard documentation, which I have already tried.

Thanks V


1 Answer(s)