I have build a page to insert district name but on inserting if a field is blank then its not displaying any message.
Below is my code:
@model ROMvcApplication.Models.districtModelClass
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_DashboardAdminLayout.cshtml";
}
<!-- Display Section -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Add/Modify District</h1>
</div>
<!-- /.container-fluid -->
@using (@Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div ng-app="MyApp" ng-controller="MyController">
<table width="100%" border="0">
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td style="width: 150px">District Name<br />
<input type="text" ng-model="district_Name" style="width: 140px"/>
@Html.ValidationMessageFor(model => model.districtname, "", new { @class = "text-danger" })
</td>
<td style="width: 200px">
<br />
<input type="button" value="Add" ng-click="Add()" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top">
<table id="tblCustomers" class="table" cellpadding="0" cellspacing="0" width="600">
<tr>
<th style="width: 100px">District Id
</th>
<th style="width: 150px">District
</th>
<th style="width: 100px"></th>
</tr>
<tbody ng-repeat="m in districtModelClass">
<tr>
<td>
<span>{{m.districtid}}</span>
</td>
<td>
<span ng-hide="m.EditMode">{{m.districtname}}</span>
<input type="text" ng-model="m.districtname" ng-show="m.EditMode" />
</td>
<td>
<a class="Edit" href="javascript:;" ng-hide="m.EditMode" ng-click="Edit($index)">Edit</a>
<a class="Update" href="javascript:;" ng-show="m.EditMode" ng-click="Update($index)">Update</a>
<a class="Cancel" href="javascript:;" ng-show="m.EditMode" ng-click="Cancel($index)">Cancel</a>
<a href="javascript:;" ng-hide="m.EditMode" ng-click="Delete(m.districtid)">Delete</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
}
<!-- Ends Here -->
Models -> districtModelClass:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace ROMvcApplication.Models
{
public class districtModelClass
{
[Key]
public Int32 districtid { get; set; }
[Required(ErrorMessage="Enter district name")]
public string districtname { get; set; }
}
}