Last active
March 5, 2021 08:17
-
-
Save KadmaPraveen/0c17e9aa400aa344a3074814d963494d to your computer and use it in GitHub Desktop.
Validation In ASp.net Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
already exist validation done using asp.net core | |
[Required] | |
[Remote(action: "IsEmailInUse", controller: "Home")] | |
public string JobName { get; set; } | |
controller method | |
[AcceptVerbs("Get", "Post")] | |
[AllowAnonymous] | |
public async Task<IActionResult> IsJobNameInUse(string JobName) | |
{ | |
ScheduleDapper group = ScheduleDapper.CheckDuplicateJobName(JobName); | |
if (group == null) | |
{ | |
return Json(true); | |
} | |
else | |
{ | |
return Json($"JobName {JobName} is already in use."); | |
} | |
} | |
Html | |
@Html.TextBoxFor(model => model.JobName, new {placeholder="Job Name", htmlAttributes = new { @class = "form-control" } }) | |
script files | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js"></script> | |
Note: here order of script is importent | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment