I created an Identity project, using .net core 3 version. I generated a Migrations file, and Startup.cs with some configuration.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
But how to modify the rules for creating passwords during registration?
enter image description here
Here is a completed custom validation demo, you can select the parts you need to change:
1.Create UserLoginDto.cs class and set validation for email, password and create UserRegistrationDto.cs class to register and set validation for all properties
public class UserRegistrationDto
{
[Required(ErrorMessage = "Name is required")]
[StringLength(100)]
public string Name { get; set; }
[EmailAddress(ErrorMessage = "Invalid email address")]
[Required(ErrorMessage = "Email is required")]
public string Email { get; set; }
[Required(ErrorMessage = "Password is required")]
[RegularExpression(#"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public string Password { get; set; }
[Required(ErrorMessage = "Confirm password is required")]
[Compare("Password", ErrorMessage = "The Password and Confirm Password do not match.")]
public string ConfirmPassword { get; set; }
public string PhoneNumber { get; set; }
}
public class UserLoginDto
{
[Required(ErrorMessage = "Email is required")]
[EmailAddress(ErrorMessage = "Invalid email address")]
public string Email { get; set; }
[Required(ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "Remember me")]
public bool RememberMe { get; set; }
}
2.Inject the UserManager and SignInManager identity classes into their constructors.
public class AccountController : Controller
{
private readonly UserManager<IdentityUser> userManager;
private readonly SignInManager<IdentityUser> signInManager;
public AccountController(UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager)
{
this.userManager = userManager;
this.signInManager = signInManager;
}
3.Create a register and login method like this
public class AccountController : Controller
{
private readonly UserManager<IdentityUser> userManager;
private readonly SignInManager<IdentityUser> signInManager;
public AccountController(UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager)
{
this.userManager = userManager;
this.signInManager = signInManager;
}
[HttpGet, AllowAnonymous]
public IActionResult Register()
{
UserRegistrationDto model = new UserRegistrationDto();
return View(model);
}
[HttpPost, AllowAnonymous]
public async Task<IActionResult> Register(UserRegistrationDto request)
{
if (ModelState.IsValid)
{
var userCheck = await userManager.FindByEmailAsync(request.Email);
if (userCheck == null)
{
var user = new IdentityUser
{
UserName = request.Email,
NormalizedUserName = request.Email,
Email = request.Email,
PhoneNumber = request.PhoneNumber,
EmailConfirmed = true,
PhoneNumberConfirmed = true,
};
var result = await userManager.CreateAsync(user, request.Password);
if (result.Succeeded)
{
return RedirectToAction("Login");
}
else
{
if (result.Errors.Count() > 0)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("message", error.Description);
}
}
return View(request);
}
}
else
{
ModelState.AddModelError("message", "Email already exists.");
return View(request);
}
}
return View(request);
}
[HttpGet]
[AllowAnonymous]
public IActionResult Login()
{
UserLoginDto model = new UserLoginDto();
return View(model);
}
[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> Login(UserLoginDto model)
{
if (ModelState.IsValid)
{
var user = await userManager.FindByEmailAsync(model.Email);
if (user != null && !user.EmailConfirmed)
{
ModelState.AddModelError("message", "Email not confirmed yet");
return View(model);
}
if (await userManager.CheckPasswordAsync(user, model.Password) == false)
{
ModelState.AddModelError("message", "Invalid credentials");
return View(model);
}
var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, true);
if (result.Succeeded)
{
await userManager.AddClaimAsync(user, new Claim("UserRole", "Admin"));
return RedirectToAction("Dashboard");
}
else if (result.IsLockedOut)
{
return View("AccountLocked");
}
else
{
ModelState.AddModelError("message", "Invalid login attempt");
return View(model);
}
}
return View(model);
}
[Authorize]
public IActionResult Dashboard()
{
return View();
}
public async Task<IActionResult> Logout()
{
await signInManager.SignOutAsync();
return RedirectToAction("login", "account");
}
4.Create the Register.cshtml view
#model UserRegistrationDto
#{
ViewData["Title"] = "Register";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container">
<h1>Register</h1>
#Html.ValidationSummary()
<form asp-action="Register" asp-controller="Account" method="post">
<div class="registerdiv">
<div class="form-group col-sm-12">
<label asp-for="#Model.Name" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.TextBoxFor(m => m.Name, new { placeholder = "First Name", #class = "form-control" })
#Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<div class="form-group col-sm-12">
<label asp-for="#Model.Email" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.TextBoxFor(m => m.Email, new { placeholder = "Email", #class = "form-control" })
#Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group col-sm-12">
<label asp-for="#Model.PhoneNumber" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.TextBoxFor(m => m.PhoneNumber, new { placeholder = "Phone Number", #class = "form-control" })
#Html.ValidationMessageFor(m => m.PhoneNumber)
</div>
</div>
<div class="form-group col-sm-12">
<label asp-for="#Model.Password" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.TextBoxFor(m => m.Password, new { placeholder = "Password", #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group col-sm-12">
<label asp-for="#Model.ConfirmPassword" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.PasswordFor(m => m.ConfirmPassword, new { placeholder = "Confirm Password", #class = "form-control" })
#Html.ValidationMessageFor(m => m.ConfirmPassword)
</div>
</div>
<div class="form-group">
<div class="col-sm-12 btn-submit">
<button type="submit" class="btn btn-success">Sign Up</button>
</div>
</div>
</div>
</form>
</div>
<style>
.validation-summary-errors,.field-validation-error {
color: red;
}
</style>
5.Create the Login.cshmt view
#model UserLoginDto
#{
ViewData["Title"] = "Login";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container">
<h1>Login</h1>
#Html.ValidationSummary()
<form asp-action="Login" asp-controller="Account" method="post">
<div class="logindiv">
<div class="form-group col-sm-12">
<label asp-for="#Model.Email" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.TextBoxFor(m => m.Email, new { placeholder = "Email", #class = "form-control" })
#Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group col-sm-12">
<label asp-for="#Model.Password" class="col-lg-3 control-label"></label>
<br>
<div class="col-lg-9">
#Html.PasswordFor(m => m.Password, new { placeholder = "Password", #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group">
<div class="col-sm-12 btn-submit">
<button type="submit" class="btn btn-success">Login</button>
<a asp-action="Register" asp-controller="account">Don't have an account?Click to Register</a>
</div>
</div>
</div>
</form>
</div>
6.Create a partial view of _LoginPartial.cshmtl, display the login user name, and the logout button will appear after logging in to the website
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>#ViewData["Title"] - WebApplication221</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">WebApplication221</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<partial name="_LoginPartial" />
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
#RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
© 2022 - WebApplication221 - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
#RenderSection("Scripts", required: false)
</body>
</html>
7.Set the custom redirect URL path from ConfigureServices in the Startup.cs class.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/account/login";
options.LogoutPath = $"/account/logout";
options.AccessDeniedPath = $"/account/accessDenied";
});
services.AddControllersWithViews();
services.AddRazorPages();
}
8.Result:
Related
hi I am new in EF core Razor pages .and I am using Code First Approach .So I want to implement Male Female Radio Button Property .I generated The migration Adding Property But I Am not Understanding How to Get That Values In Razor Page.
My ApplicationUser.cs Class
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmployeCode { get; set; }
public string Designation { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime DateOfJoining { get; set; }
public string EmergencyNo { get; set; }
public string AdharNo { get; set; }
//Department dropdown and city and country thing
public string Gender { get; set; }
public string[] Genders = new[] { "Male", "Female", };
public string Country { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
}
I added Gender Here.Then Added Migration.
My RegisterModel class
//[AllowAnonymous]
//[Authorize(Roles = StaticDetails.AdminEndUser)]
public class RegisterModel : PageModel
{
private readonly SignInManager<IdentityUser> _signInManager;
private readonly UserManager<IdentityUser> _userManager;
private readonly ILogger<RegisterModel> _logger;
////comented the Iemailsender because its causing error.
// private readonly IEmailSender _emailSender;
//// added by me for dependency injection;
private readonly RoleManager<IdentityRole> _roleManager;
private readonly ApplicationDbContext _db;
public RegisterModel(
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager,
ILogger<RegisterModel> logger,
// IEmailSender emailSender,
////added by me for constructor for the upper used dependency injection;
RoleManager<IdentityRole> roleManager,
ApplicationDbContext db)
{
_userManager = userManager;
_signInManager = signInManager;
_logger = logger;
// _emailSender = emailSender;
////added by me for upper used constructor;
_roleManager = roleManager;
_db = db;
}
[BindProperty]
public InputModel Input { get; set; }
public string ReturnUrl { get; set; }
public IList<AuthenticationScheme> ExternalLogins { get; set; }
public class InputModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
//added by me
//[BindProperty]
//public string Gender { get; set; }
//public string[] Genders = new[] { "Male", "Female", "Unspecified" };
//[DataType(DataType.Date)]
//[Column(TypeName = "Date")]
//public DateTime DateOfBirth { get; set; }
[Required]
[RegularExpression("([a-zA-Z][a-zA-Z ]+)", ErrorMessage = "Only alphabets are allowed")]
//public string FullName { get; set; }
public string FirstName { get; set; }
[RegularExpression("([a-zA-Z][a-zA-Z ]+)", ErrorMessage = "Only alphabets are allowed")]
public string LastName { get; set; }
[Required]
[RegularExpression("(^.*$)", ErrorMessage = "Invalid EmployeCode")]
public string EmployeCode { get; set; }
public string Designation { get; set; }
//[DataType(DataType.Date)]
//[Column(TypeName = "Date")]
[Required]
[BindProperty]
public DateTime DateOfBirth { get; set; }
[Required]
[BindProperty]
public DateTime DateOfJoining { get; set; }
[Required]
[Display(Name = "Emergency No")]
[MaxLength(10), MinLength(10)]
public string EmergencyNo { get; set; }
[Required]
[MaxLength(12),MinLength(12)]
public string AdharNo { get; set; }
[Required]
public string Address { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
[Required]
[Display(Name = "Phone Number")]
[MaxLength(10)/*, MinLength(10)*/]
public string PhoneNumber { get; set; }
[Required]
[BindProperty]
public string Gender { get; set; }
public string[] Genders = new[] { "Male", "Female", };
}
public class MobileUniqueAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(
object value, ValidationContext validationContext)
{
var _context = (ApplicationDbContext)validationContext.GetService(typeof(ApplicationDbContext));
var entity = _context.ApplicationUser.SingleOrDefault(e => e.PhoneNumber == value.ToString());
if (entity != null)
{
return new ValidationResult(/*GetErrorMessage(value.ToString())*/"Hey The MobileNo is Alrdy Present");
}
return ValidationResult.Success;
}
public string GetErrorMessage(string mobile)
{
return $"Mobile {mobile} is already in use.";
}
//ValidationResult validphone = IsValid(object value, ValidationContext validationContext);
}
public async Task OnGetAsync(string returnUrl = null)
{
ReturnUrl = returnUrl;
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
}
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
//var _context = (ApplicationDbContext)_db.ApplicationUser(typeof(ApplicationDbContext));
returnUrl = returnUrl ?? Url.Content("~/");
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (ModelState.IsValid)
{
//// var user = new Identityuser { UserName = Input.Email, Email = Input.Email };...I edited it because in Applicationuser class i am putting the name,address,city,postal code.
var user = new ApplicationUser
{
UserName = Input.Email,
Email = Input.Email,
FirstName = Input.FirstName,
LastName = Input.LastName,
EmployeCode = Input.EmployeCode,
Designation = Input.Designation,
//DateOfBirth= Convert.ToDateTime("DateOfBirth"),
DateOfBirth = Input.DateOfBirth,
DateOfJoining = Input.DateOfJoining,
EmergencyNo = Input.EmergencyNo,
AdharNo = Input.AdharNo,
Address = Input.Address,
City = Input.City,
PostalCode = Input.PostalCode,
PhoneNumber = Input.PhoneNumber,
Gender = Input.Gender,
Genders = Input.Genders
};
////after dependency injection we come to after post handler.and in below line they r creating the user.
var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
////added by me if this is successful we want chk if role exits in the detabase.
////if admin user doesnot exits we want to creat it.
////StaticDetails class SD created by me.
if (!await _roleManager.RoleExistsAsync(StaticDetails.AdminEndUser))
{
await _roleManager.CreateAsync(new IdentityRole(StaticDetails.AdminEndUser));
}
if (!await _roleManager.RoleExistsAsync(StaticDetails.HrEndUser))
{
await _roleManager.CreateAsync(new IdentityRole(StaticDetails.HrEndUser));
}
if (!await _roleManager.RoleExistsAsync(StaticDetails.ItEndUser))
{
await _roleManager.CreateAsync(new IdentityRole(StaticDetails.ItEndUser));
}
if (!await _roleManager.RoleExistsAsync(StaticDetails.EmployeeEndUser))
{
await _roleManager.CreateAsync(new IdentityRole(StaticDetails.EmployeeEndUser));
}
////roles are created now have to assign it to a user.
////adminuser for now.means when i will creat it will by default take adminuser.
await _userManager.AddToRoleAsync(user, StaticDetails.EmployeeEndUser);
_logger.LogInformation("User created a new account with password.");
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
protocol: Request.Scheme);
// await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
// $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
}
else
{
await _signInManager.SignInAsync(user, isPersistent: false);
return LocalRedirect(returnUrl);
}
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
// If we got this far, something failed, redisplay form
return Page();
}
}
My Register.cshtml class
#page
#model RegisterModel
#{
ViewData["Title"] = "Register";
}
#*<h1>#ViewData["Title"]</h1>*#
<h2 class="text-info pt-2 pb-3">Create a new account</h2>
<div class="row bg-white border">
<div class="col-md-8">
<form asp-route-returnUrl="#Model.ReturnUrl" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.FirstName"></label>
</div>
<div class="col-8">
<input asp-for="Input.FirstName" class="form-control" />
</div>
<span asp-validation-for="Input.FirstName" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.LastName"></label>
</div>
<div class="col-8">
<input asp-for="Input.FirstName" class="form-control" />
</div>
<span asp-validation-for="Input.FirstName" class="text-danger"></span>
</div>
</div>
#foreach (var gender in Model.ReturnUrl.Genders)
{
#Html.RadioButtonFor(model => model.Gender, gender) #gender<br />
}
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.EmployeCode"></label>
</div>
<div class="col-8">
<input asp-for="Input.EmployeCode" class="form-control" />
</div>
<span asp-validation-for="Input.EmployeCode" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.Designation"></label>
</div>
<div class="col-8">
<input asp-for="Input.Designation" class="form-control" />
</div>
<span asp-validation-for="Input.Designation" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.DateOfBirth"></label>
</div>
<div class="col-8">
<input asp-for="Input.DateOfBirth" class="form-control" />
</div>
<span asp-validation-for="Input.DateOfBirth" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.DateOfJoining"></label>
</div>
<div class="col-8">
<input asp-for="Input.DateOfJoining" class="form-control" />
</div>
<span asp-validation-for="Input.DateOfJoining" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.Email"></label>
</div>
<div class="col-8">
<input asp-for="Input.Email" class="form-control" />
</div>
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.PhoneNumber"></label>
</div>
<div class="col-8">
<input asp-for="Input.PhoneNumber" class="form-control" />
</div>
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.EmergencyNo"></label>
</div>
<div class="col-8">
<input asp-for="Input.EmergencyNo" class="form-control" />
</div>
<span asp-validation-for="Input.EmergencyNo" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.AdharNo"></label>
</div>
<div class="col-8">
<input asp-for="Input.AdharNo" class="form-control" />
</div>
<span asp-validation-for="Input.AdharNo" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.Address"></label>
</div>
<div class="col-8">
<input asp-for="Input.Address" class="form-control" />
</div>
<span asp-validation-for="Input.Address" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.City"></label>
</div>
<div class="col-8">
<input asp-for="Input.City" class="form-control" />
</div>
<span asp-validation-for="Input.City" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.PostalCode"></label>
</div>
<div class="col-8">
<input asp-for="Input.PostalCode" class="form-control" />
</div>
<span asp-validation-for="Input.PostalCode" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.Password"></label>
</div>
<div class="col-8">
<input asp-for="Input.Password" class="form-control" />
</div>
<span asp-validation-for="Input.Password" class="text-info font-italic">.The Password must be at least 6 and at max 100 characters long,atleast one alpha numeric char and contain atleast one uppercase(A-Z).</span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
<label asp-for="Input.ConfirmPassword"></label>
</div>
<div class="col-8">
<input asp-for="Input.ConfirmPassword" class="form-control" />
</div>
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-4">
</div>
<div class="col-8">
<button type="submit" class="btn btn-success form-control">Register </button>
</div>
</div>
</div>
</form>
</div>
</div>
#*<div class="row">
<div class="col-md-4">
<form asp-route-returnUrl="#Model.ReturnUrl" method="post">
<h4>Create a new account.</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.ConfirmPassword"></label>
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>*#
#*<div class="col-md-6 col-md-offset-2">
<section>
<h4>Use another service to register.</h4>
<hr />
#{
if ((Model.ExternalLogins?.Count ?? 0) == 0)
{
<div>
<p>
There are no external authentication services configured. See this article
for details on setting up this ASP.NET application to support logging in via external services.
</p>
</div>
}
else
{
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="#Model.ReturnUrl" method="post" class="form-horizontal">
<div>
<p>
#foreach (var provider in Model.ExternalLogins)
{
<button type="submit" class="btn btn-primary" name="provider" value="#provider.Name" title="Log in using your #provider.DisplayName account">#provider.DisplayName</button>
}
</p>
</div>
</form>
}
}
</section>
</div>
</div>*#
#section Scripts {
<partial name="_ValidationScriptsPartial" />
}
My problem is Did i operated The right way.in That Case How To Get That Genders List.
public class RegisterModel : PageModel
{
...
[BindProperty]
public InputModel Input { get; set; }
public class InputModel
{
...
[Required]
[BindProperty]
public string Gender { get; set; }
public string[] Genders = new[] { "Male", "Female", };
}
...
}
From the above code, we can see you are using the InputModel to bind the property and the Genders/Gender, so, in the OnGetAsync method, we need to create the Input model instance, to prevent the Input model NullReferenceException. Code like this:
public async Task OnGetAsync(string returnUrl = null)
{
ReturnUrl = returnUrl;
Input = new InputModel();
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
}
Then, when displaying the radio button in the view page, the code should be like this: access the Genders via the Input, and set the selected value using the Input.Gender.
#foreach (var gender in Model.Input.Genders)
{
#Html.RadioButtonFor(model => model.Input.Gender, gender) #gender<br />
}
After that, the result is like this: we can get the selected gender via the Input.Gender property.
I'm facing an odd issue here.
I have a page where i have setup a PageRemote attribute to validate a field, and on the same page, i have 2 buttons that each call a distinct handler using the asp-page-handler property (1 to update the content, the other to delete it).
If i remove the PageRemote validation, the handlers for both buttons are triggered as expected, but when i leave the PageRemote validation on the page, the buttons specific handlers are not called, although the PageRemote handler is correctly triggered.
Furthermore, when leaving the PageRemote validation on the page, if i force its validation to return false, then afterwards the buttons trigger their respective handler, but if i do not force it, then the behaviour is as described earlier, where the handlers are not triggered.
Can someone explain me if there is a catch on using these two things on the same page, and/or how to overcome this?
Below is a sample of the page code:
public class EditModel : PageModel
{
private IConfiguration _configuration;
[Required(ErrorMessageResourceType = typeof(ErrorMessages),
ErrorMessageResourceName = nameof(ErrorMessages.SlugRequired))]
[MinLength(3, ErrorMessageResourceType = typeof(ErrorMessages),
ErrorMessageResourceName = nameof(ErrorMessages.SlugMinLength))]
[MaxLength(128, ErrorMessageResourceType = typeof(ErrorMessages),
ErrorMessageResourceName = nameof(ErrorMessages.SlugMaxLength))]
[RegularExpression(#"^[0-9a-zA-Z_/-]*$", ErrorMessageResourceType = typeof(ErrorMessages),
ErrorMessageResourceName = nameof(ErrorMessages.SlugAllowedCharacters))]
[PageRemote(ErrorMessageResourceType = typeof(ErrorMessages),
ErrorMessageResourceName = nameof(ErrorMessages.SlugDuplicate),
AdditionalFields = "__RequestVerificationToken,GenericContentDTO.GenericContent.GenericContentId",
HttpMethod = "post",
PageHandler = "CheckSlug")]
[Display(Name = "URL Title")]
[BindProperty]
public string Slug { get; set; }
[TempData]
public string FormResultMessage { get; set; }
[BindProperty]
public GenericContentDTO GenericContentDTO { get; set; }
public EditModel(IConfiguration configuration)
{
_configuration = configuration;
}
public IActionResult OnGet(Guid genericContentId)
{
if (genericContentId.ToString() == "")
{
return NotFound();
}
...
Code to load content
...
return Page();
}
public async Task<IActionResult> OnPostUpdate()
{
if (!ModelState.IsValid)
{
return Page();
}
...
Code to update content
...
return RedirectToPage(new { GenericContentId = GenericContentDTO.GenericContent.GenericContentId });
}
public IActionResult OnPostDelete()
{
...
Code to delete content
}
public JsonResult OnPostCheckSlug()
{
var token = HttpContext.Session.GetString("APIAuthorizationToken");
CheckSlugDTO CheckSlug = new CheckSlugDTO
{
Slug = Slug,
ContentId = GenericContentDTO.GenericContent.GenericContentId,
Exists = true
};
CheckSlug = APICommunicationHelper.PostData<CheckSlugDTO>(CheckSlug, _configuration["AppConfigs:APIAddress"] + "api/CheckGenericContentSlugExistance", token);
return new JsonResult(!CheckSlug.Exists);
}
}
And of the Razor Code:
#page "{GenericContentId:Guid}"
#model MyProject.Pages.Generic_Contents.EditModel
#{
}
<form method="post" id="editForm" name="editForm" enctype="multipart/form-data">
<h3>#TempData["FormResultMessage"]</h3>
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#main">Main</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#meta">Meta</a></li>
</ul>
<div class="tab-content">
<div id="main" class="tab-pane active">
<br />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
#Html.HiddenFor(model => model.GenericContentDTO.GenericContent.GenericContentId)
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.Title" class="control-label"></label>
<input asp-for="GenericContentDTO.GenericContent.Title" class="form-control" />
<span asp-validation-for="GenericContentDTO.GenericContent.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Slug" class="control-label"></label>
<input asp-for="Slug" class="form-control" />
<span asp-validation-for="Slug" class="text-danger"></span>
</div>
<div class="form-group row">
<div class="col-4">
<label asp-for="GenericContentDTO.MainImage" class="control-label"></label>
<input asp-for="GenericContentDTO.MainImage" type="file" class="form-control" />
</div>
</div>
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.Summary" class="control-label"></label>
#Html.TextAreaFor(model => model.GenericContentDTO.GenericContent.Summary, new { #class = "form-control", #rows = 5 })
<span asp-validation-for="GenericContentDTO.GenericContent.Summary" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.ContentText" class="control-label"></label>
#Html.TextAreaFor(model => model.GenericContentDTO.GenericContent.ContentText, new { #class = "form-control editorHtml" })
</div>
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.IsActive" class="control-label"></label>
#Html.CheckBoxFor(model => model.GenericContentDTO.GenericContent.IsActive)
</div>
</div>
<div id="meta" class="tab-pane fade">
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.MetaDescription" class="control-label"></label>
#Html.TextAreaFor(model => model.GenericContentDTO.GenericContent.MetaDescription, new { #class = "form-control", #rows = 5 })
<span asp-validation-for="GenericContentDTO.GenericContent.MetaDescription" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="GenericContentDTO.GenericContent.MetaKeywords" class="control-label"></label>
#Html.TextAreaFor(model => model.GenericContentDTO.GenericContent.MetaKeywords, new { #class = "form-control", #rows = 5 })
<span asp-validation-for="GenericContentDTO.GenericContent.MetaKeywords" class="text-danger"></span>
</div>
</div>
<div class="form-group text-right">
<a asp-area="" asp-page="/Generic-Contents" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-danger" asp-page-handler="Delete">Delete Content</button>
<button type="submit" class="btn btn-primary" asp-page-handler="Update">Update Content</button>
</div>
</div>
</form>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Thanks
I use Modal and Load Partial view to it, but if I keep fields blank no validation happened and modal closed after click submit button.
Also I use Required annotation in my viewmodel. Also when I click submit it calls action direct in controller.
My Question: how can I display a validation message in modal form?
#section scripts{
<script>
function onFailureDefault(data) {
$("#AddOrderDetailModalDiv").valid()
}
function OpenAddOrderDetailTempItemOnSuccess() {
$("#AddOrderDetailModalDiv").modal("show");
}
function AddOrderDetailTempItemOnComplete() {
$("#AddOrderDetailModalDiv").modal("hide");
}
</script>
}
#model OrderDetailViewModel
#using (Html.BeginForm("AddOrderDetailTempItem", "Orders", FormMethod.Post, new
{
id = "AddForm",
#data_ajax = "true",
#data_ajax_method = "post",
#data_ajax_update = "#OrderDetailList",
#data_ajax_failure = "onFailureDefault",
#data_ajax_complete = "AddOrderDetailTempItemOnComplete"
}))
{
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg" role="document">
<div class="modal-content">
<div class="modal-header bg-warning white">
<h5 class="modal-title" id="exampleModalCenterTitle">#( Model.ID > 0 ? "Edit Product" : "Add Product" )</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div>
#Html.HiddenFor(m => m.ID)
<div asp-validation-summary="All" class="text-danger"></div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label asp-for="ProductId" class="control-label"></label>
#Html.DropDownListFor(m => m.ProductId, Model.ProductsList, " ", htmlAttributes: new { #class = "select2 form-control" })
<span asp-validation-for="ProductId" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label asp-for="Quantity" class="control-label"></label>
<input asp-for="Quantity" required class="form-control" />
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label asp-for="Unit" class="control-label"></label>
#Html.DropDownListFor(m => m.Unit, Model.QuantityUnitsList, " ", htmlAttributes: new { #class = "form-control" })
<span asp-validation-for="Unit" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label asp-for="UnitPrice" class="control-label"></label>
<input asp-for="UnitPrice" class="form-control" />
</div>
</div>
<label id="ErrorMessage" asp-for="ErrorMessage" class="form-control" />
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Add Product" id="postSave" class="btn btn-primary" />
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
}
[HttpPost]
public ActionResult AddOrderDetailTempItem(OrderDetailViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
List<OrderDetailViewModel> models = OrderDetailViewModelList;
var product = productService.SingleBy(model.ProductId);
if (model.ID > 0)
{
var updatedItem = models.Find(m => m.ID == model.ID);
updatedItem.Quantity = model.Quantity;
updatedItem.ProductId = model.ProductId;
updatedItem.UnitPrice = model.UnitPrice;
updatedItem.TotalPrice = model.Quantity * model.UnitPrice;
updatedItem.ProductName = product.Name;
updatedItem.Unit = model.Unit;
updatedItem.QuantityUnitsText = ((QuantityUnits)model.Unit).ToString();
updatedItem.isActive = true;
//mapper.Map(model,updatedItem);///
}
else
{
models.Add(new OrderDetailViewModel
{
ID = counter - 1,//models.Count + 1,
Quantity = model.Quantity,
ProductId = model.ProductId,
UnitPrice = model.UnitPrice,
TotalPrice = model.Quantity * model.UnitPrice,
ProductName = product.Name,
Unit = model.Unit,
QuantityUnitsText = ((QuantityUnits)model.Unit).ToString(),
isActive = true,
});
counter -= 1;
}
OrderDetailViewModelList = models;
return PartialView("_OrderDetailGridPartial", OrderDetailViewModelList.Where(a => a.isActive == true).ToList());
}
Parent View
#using (Html.BeginForm("AddOrder", "Orders", FormMethod.Post, new
{
id = "AddForm",
#data_ajax = "true",
#data_ajax_method = "post",
//#data_ajax_update = "#OrderDetailList",
#data_ajax_complete = "AddOrderOnComplete"
}))
{
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label asp-for="DeliveryDate" class="control-label"></label>
<input asp-for="DeliveryDate" class="form-control" type="date" />
<span asp-validation-for="DeliveryDate" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label asp-for="OrderDate" class="control-label"></label>
<input asp-for="OrderDate" class="form-control" disabled type="date" />
<span asp-validation-for="OrderDate" class="text-danger"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label asp-for="CustomerId" class="control-label"></label>
#Html.DropDownListFor(m => m.CustomerId, Model.CustomersList, "Please select", htmlAttributes: new { #class = "select2 form-control" })
<span asp-validation-for="CustomerId" class="text-danger"></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label asp-for="Notes" class="control-label"></label>
<textarea asp-for="Notes" rows="4" class="form-control"></textarea>
<span asp-validation-for="Notes" class="text-danger"></span>
</div>
</div>
</div>
<div class="content-header row">
<div class="content-header-left col-md-9 col-12 mb-2">
</div>
<div class="content-header-right text-md-right col-md-3 col-12">
<div class="form-group breadcrum-right">
<button type="button" class="btn bg-gradient-danger mr-1 mb-1 waves-effect waves-light">
<i class="feather icon-package">
#Html.ActionLink("Add Product", "AddOrderDetailTempItem", "Orders", routeValues: null, htmlAttributes: new
{
Style = "color:White;font-family:'Montserrat';padding-left: 10px;",
#data_ajax = "true",
#data_ajax_method = "Get",
#data_ajax_update = "#AddOrderDetailModalDiv",
#data_ajax_failure = "onFailureDefault",
#data_ajax_success = "OpenAddOrderDetailTempItemOnSuccess",
})
</i>
</button>
</div>
</div>
</div>
<div id="OrderDetailList">
<partial name="_OrderDetailGridPartial.cshtml" model="Model.OrderDetailViewModel" />
</div>
<div class="form-group col-sm-3">
<input type="submit" name="btn" value="Save" class="btn btn-primary" />
</div>
}
My Model
public class OrderDetailViewModel
{
public int ID { get; set; }
public int OrderId { get; set; }
[Required(ErrorMessage = "حقل إجباري")]
[Display(Name ="Product Name")]
public int ProductId { get; set; }
public string ProductName { get; set; }
[Required(ErrorMessage = "حقل إجباري")]
public int Unit { get; set; }
[Required(ErrorMessage = "حقل إجباري")]
public int Quantity { get; set; }
[Required(ErrorMessage = "حقل إجباري")]
public decimal UnitPrice { get; set; }
public decimal TotalPrice { get; set; }
public SelectList ProductsList { get; set; }
public SelectList QuantityUnitsList { get; set; }
public bool isActive { get; set; }
public string QuantityUnitsText { get; set; }
public string ErrorMessage { get; set; }
}
Your code is not complete,so I provide a work demo,you can check it.
Model:
public class Student
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
}
_OrderDetailGridPartial:
#model Student
<div id="MyModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" >
<h4 class="modal-title" >Update Role</h4>
</div>
<div class="modal-body">
<form id="myform" method="post">
<div>
<label>Id</label>
<input asp-for="Id" />
<span asp-validation-for="Id" class="text-danger"></span>
</div>
<div>
<label>Name</label>
<input asp-for="Name" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<button id="button" class="btn btn-default">Save</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Index View:
<button id="showmodal" class="btn btn-danger">
Click
</button>
<div id="partical">
<partial name="~/Views/Shared/_OrderDetailGridPartial.cshtml" />
</div>
#section scripts{
<script>
$("#showmodal").click(function () {
$('#MyModal').modal('show');
})
$("#button").click(function (e) {
e.preventDefault();
var model = $('#myform').serialize();
console.log(model);
$.ajax({
type: 'POST',
url: 'home/index',
async: false,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data: model,
success: function (result) {
$('#partical').html(result);
$('#MyModal').modal('show');
}
});
})
</script>
}
Action:
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(Student student)
{
if (!ModelState.IsValid)
{
return PartialView("_OrderDetailGridPartial",student);
}
return View();
}
Test result
I am trying to make a default value take application, My view loads all my value with one editor. My controller is not getting any of the data from the view?
I want to be able to edit all my value at the same time? How can I do this
Model Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Demo.Models.Admin
{
public class MerchantPackageTransactionModel
{
public MerchantPackageTransactionModel()
{
FeatureList = new List<PackageFeatureModel>();
}
public int PackageId { get; set; }
public string PackageName { get; set; }
public string Image { get; set; }
public List<PackageFeatureModel> FeatureList { get; set; }
}
public class PackageFeatureModel
{
public int FeatureId { get; set; }
public string FeatureName { get; set; }
public string Type { get; set; }
public string DefaultValue { get; set; }
public string Value { get; set; }
}
}
View Code
#model Demo.Models.Admin.MerchantPackageTransactionModel
#{
ViewBag.Title = "CreatePackageTransaction";
Layout = "~/Themes/green/Views/Shared/_AdminDashboard.cshtml";
}
#using (Html.BeginForm())
{
<fieldset>
<legend>MerchantPackageTransactionModel</legend>
#Html.HiddenFor(model => model.PackageId)
<div class="editor-label">
#Html.LabelFor(model => model.PackageName)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.PackageName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Image)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Image)
</div>
#foreach (var item in Model.FeatureList)
{
#Html.HiddenFor(model => item.FeatureId)
<div class="editor-label">
#Html.Label("Feature Name")
</div>
<div class="editor-field">
#Html.DisplayFor(model => item.FeatureName)
</div>
<div class="editor-label">
#Html.Label("Type")
</div>
<div class="editor-field">
#Html.DisplayFor(model => item.Type)
</div>
<div class="editor-label">
#Html.Label("Default Value")
</div>
<div class="editor-field">
#Html.DisplayFor(model => item.DefaultValue)
</div>
<div class="editor-label">
#Html.Label("Value")
</div>
<div class="editor-field">
#Html.EditorFor(model => item.Value)
</div>
}
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
Controller code
public ActionResult CreatePackageTransaction(MerchantPackageTransactionModel objMerchantPackageTransactionModel)
{
foreach (var item in objMerchantPackageTransactionModel.FeatureList)
{
if (ModelState.IsValid)
{
GR.InsertOrUpdate(item);
}
}
GR.Save();
return View(objMerchantPackageTransactionModel);
}
What is happening is, because you are using
#Html.EditorFor(model => item.Value)
that is a command directly associated with the model and it is being used to render an input not accessed from the model (item), it is rendering an input html with the "wrong" name:
<input class="text-box single-line" id="item_Value" name="item.Value" type="text" value="">
when it should be
<input class="text-box single-line" id="FeatureList_0__Value" name="FeatureList[0].Value" type="text" value="">
And, as name does not match with the one from the model (FeatureList), the framework cannot do the automatic bind when the request hits the server.
You have a two options to fix it:
Create the html by hand, setting the correct (expected) name; or:
In the iteration use an index so that the EditorFor generates the input with the expected name:
#{
var index = 0;
}
#foreach (var item in Model.FeatureList)
{
#Html.HiddenFor(model => model.FeatureList[index].FeatureId)
<div class="editor-label">
#Html.Label("Feature Name")
</div>
<div class="editor-field">
#Html.DisplayFor(model => model.FeatureList[index].FeatureName)
</div>
<div class="editor-label">
#Html.Label("Type")
</div>
<div class="editor-field">
#Html.DisplayFor(model => model.FeatureList[index].Type)
</div>
<div class="editor-label">
#Html.Label("Default Value")
</div>
<div class="editor-field">
#Html.DisplayFor(model => model.FeatureList[index].DefaultValue)
</div>
<div class="editor-label">
#Html.Label("Value")
</div>
<div class="editor-field">
#Html.EditorFor(model => model.FeatureList[index].Value)
</div>
index++;
}
I have tested and it just work worked fine. Have a nice weekend! Regards.
I am posting a form back to the server, the values are always null.
Model:
public class RDetailsViewModel
{
public RDetailsMaster RDetailsMaster { get; set; }
public ETransaction ETransaction { get; set; }
}
public class RDetailsMaster
{
[Required]
public List<QE_DROPDOWN_MST> Master_EQ { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_BASIS { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_TE { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_ALOP { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_RISK { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_EXCESS { get; set; }
[Required]
public List<QE_DROPDOWN_MST> Master_CType { get; set; }
}
Controller:
[HttpPost]
public ActionResult RDetails(RDetailsViewModel ObjR)
{
return view();
}
My View :
#model QMS_ERater.ViewModels.RDetailsViewModel
#{
ViewBag.Title = "RDetails";
}
<script src="~/Scripts/EAR/RDetails.js"></script>
#using (Html.BeginForm("RDetails", "RDetails", FormMethod.Post))
{
<h2>RDetails</h2>
<div class="well well-sm">
<div id="divDetail101" runat="server">
<div class="row">
<div class="col-sm-4">
<span style="vertical-align: top; color: Red">*</span> EQ :
</div>
<div class="col-sm-3">
#Html.DropDownListFor(m => m.ETransation.EQ, new SelectList(Model.RDetailsMaster.Master_EQ, "VALUE", "DESCRIPTION"), "--Select--", new { style = "width: 100%;" })
</div>
<div class="col-sm-2">
<span style="vertical-align: top; color: Red">*</span> On First Loss Basis :
</div>
<div class="col-sm-3">
#Html.DropDownListFor(m => m.ETransation.BASIS, new SelectList(Model.RDetailsMaster.Master_BASIS, "VALUE", "DESCRIPTION"), "--Select--", new { style = "width: 100%;" })
</div>
<div class="col-sm-4">
<span style="vertical-align: top; color: Red">*</span> Terrorism :
</div>
<div class="col-sm-3">
#Html.DropDownListFor(m => m.ETransation.IS_TE, new SelectList(Model.RDetailsMaster.Master_TE, "VALUE", "DESCRIPTION"), "--Select--", new { style = "width: 100%;" })
</div>
<div class="col-sm-2">
<span style="vertical-align: top; color: Red">*</span> ALOP :
</div>
<div class="col-sm-3">
#Html.DropDownListFor(m => m.ETransation.IS_ALOP, new SelectList(Model.RDetailsMaster.Master_ALOP, "VALUE", "DESCRIPTION"), "--Select--", new { style = "width: 100%;" })
</div>
<div class="col-sm-4">
<span style="vertical-align: top; color: Red">*</span> Wet Risk :
</div>
<div class="col-sm-3">
#Html.DropDownListFor(m => m.ETransation.IS_RISK, new SelectList(Model.RDetailsMaster.Master_RISK, "VALUE", "DESCRIPTION"), "--Select--", new { style = "width: 100%;" })
</div>
</div>
</div>
<input type="submit" value="Submit" />
</div>
}
When I am trying call post method objR return NULL value for only List objects.
Any help would be greatly appreciated.
Thanks in advance!