Description:
In this example we explain that how to create Password TextBox using Html.TextBoxFor in Asp.Net MVC.or how to create Password TextBox in MVC Razor View. Here we demonstrate that how to create Password TextBox and perform Client side validation for password TextBox using Data Annotation in MVC Razor.
public class EmployeeModel
{
[Required(ErrorMessage = "Password is required.")]
public string Password { get;
set; }
[Required(ErrorMessage = "Confirmation Password is required.")]
[Compare("Password",
ErrorMessage = "Password and Confirmation
Password must match.")]
public string ConfirmPassword { get;
set; }
}
Controller:
public class EmployeeController
: Controller
{
// GET: Home
public ActionResult Index()
{
return
View();
}
[HttpPost]
public ActionResult Index(EmployeeModel
emp)
{
return
View();
}
}
View:
@model
Email_Validation_MVC.Models.PersonModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Create
Password TextBox using Html.TextBoxFor in ASP.Net MVC</title>
<style type="text/css">
body
{
font-family:
Arial;
font-size:
10pt;
}
.error
{
color:
red;
}
</style>
</head>
<body>
@using (Html.BeginForm("Index",
"Employee", FormMethod.Post))
{
<table>
<tr>
<td>Password</td>
<td>@Html.PasswordFor(m
=> m.Password)</td>
<td>@Html.ValidationMessageFor(m
=> m.Password, "", new { @class = "error" })</td>
</tr>
<tr>
<td>Confirm
Password</td>
<td>@Html.PasswordFor(m
=> m.ConfirmPassword)</td>
<td>@Html.ValidationMessageFor(m
=> m.ConfirmPassword, "", new { @class = "error" })</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"/></td>
<td></td>
</tr>
</table>
}
</body>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
</html>
This comment has been removed by the author.
ReplyDeleteAll are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information,
ReplyDeleteI love your writing style very much, I would like to suggest your blog in my dude circle, so keep on update
SEO Company in India
SEO Company in chennai
Digital Marketing Company in Chennai
Digital Marketing Company in India
great Article
ReplyDelete