What is remote validation in ASP.NET Core
Text version of the video
https://csharp-video-tutorials.blogsp...
Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Tutorial
https://www.youtube.com/playlist?list...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...
Remote validation allows a controller action method to be called using client side script. This is very useful when you want to call a server side method without a full page post back.
Remote validation example
Checking, if the provided email is already taken by another user can only be done on the server. The following IsEmailInUse() controller action method checks if the provided email is in use.
[AcceptVerbs("Get", "Post")]
[AllowAnonymous]
public async Task[IActionResult] IsEmailInUse(string email)
{ var user = await userManager.FindByEmailAsync(email); if (user == null) { return Json(true); } else { return Json($"Email {email} is already in use."); }
}
This method should respond to both HTTP GET and POST. This is the reason we specified both the HTTP verbs (Get and Post) using [AcceptVerbs] attribute.
ASP.NET Core MVC uses jQuery remote() method which in turn issues an AJAX call to invoke the server side method.
The jQuery remote() method expects a JSON response, this is the reason we are returing JSON response from the server-side method (IsEmailInUse)
ASP.NET core remote attribute
The following is the model class for the User Registration View. Notice, we have decorated the Email property with the [Remote] attribute pointing it to the action method that should be invoked when the email value changes.
public class RegisterViewModel
{ [Required] [EmailAddress] [Remote(action: "IsEmailInUse", controller: "Account")] public string Email { get; set; } // Other properties
}
ASP.NET core remote validation not working
The following 3 client-side libararies are required in the order specified for the remote validation to work. If any of them are missing or not loaded in the order specified, remote validation will not work.
[script src="~/lib/jquery/jquery.js"][/script]
[script src="~/lib/jquery-validate/jquery.validate.js"][/script]
[script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"][/script]
asp.net core logging ASP NET core remote validation | |
152 Likes | 152 Dislikes |
6,946 views views | 524K followers |
Science & Technology | Upload TimePublished on 24 Jun 2019 |
Related keywords
asp.net core docker,ajax post,asp.net guida,ajax meaning,webkinz,ajax jersey,asp.net core razor pages,webadvisor,server duties,asp.net core github,asp.net core environment variables,asp.net core 3,http://asp.net,server 2019,server status,ajax fc,ajax players,server jobs nyc,asp.net core swagger,web of dreams,weber grill parts,webtoon,serverminer,ajax cleaner,asp.net machine account,server error in '/' application,servers for minecraft,asp.net core dependency injection,webassign,asp.net core 3.0,asp.net core configuration,ajax marvel,asp.net tutorial,asp.net mvc,asp.net core tutorial,ajax ontario,ajax roster,asp.net mvc tutorial,asp.net core 3 release date,server job description,asp.net core mvc,ajax soccer,server hosting,asp.net cos'è,webcam,webmd symptom,server jobs near me,webex,asp.net core web api,ajax jquery,ajax dish soap,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server rack,server status ffxiv,asp.net zero,webcrims,server memes,asp.net core hosting,ajax tavern,webroot,ajax javascript,ajax request,serverless architecture,server resume,asp.net core 2.2,server books,webmd,webster,ajax deadpool,asp.net core signalr,server jobs,ajax paving,website,ajax greek,website builder,asp.net web api,server side rendering,weber grills,asp.net identity,serverless,asp.net core middleware,asp.net core download,asp.net download,webster bank,web store,webmail,asp.net core identity,ajax parking,webstaurant,
Không có nhận xét nào:
Đăng nhận xét