Description:-
in this example we explain that how to compare
password and confirm password in mvc4 rozar view with asp.net.
we all know that in every web application in any languages must have a Register Form in which Password and Confirm Password are two field are compulsory. So this example is very useful to compare password and confirm password in Razor view in mvc website when user is register or login into the site.
We all already use this functionality in Asp.Net website but how to use in MVC is the Question so to achieve this facility in your mvc application follow the below code
Sorting Row data in gridview Gridview Sorting
How to handle Concurrency in Linq to Sql Concurrency Example
we all know that in every web application in any languages must have a Register Form in which Password and Confirm Password are two field are compulsory. So this example is very useful to compare password and confirm password in Razor view in mvc website when user is register or login into the site.
We all already use this functionality in Asp.Net website but how to use in MVC is the Question so to achieve this facility in your mvc application follow the below code
Sorting Row data in gridview Gridview Sorting
How to handle Concurrency in Linq to Sql Concurrency Example
Index.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using IndexAttribute = System.Web.Mvc.IndexAttribute;
namespace MvcNew.Models
{
public class Index
{
[Display(Name = "Password")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "Password required")]
public string Password { get; set; }
[Display(Name = "Confirm new password")]
[Required(ErrorMessage = "Enter Confirm Password")]
[Compare ("Password", ErrorMessage = "The password and confirmation password do not match.")]
[DataType(DataType.Password)]
public string confirm_password { get; set; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using IndexAttribute = System.Web.Mvc.IndexAttribute;
namespace MvcNew.Models
{
public class Index
{
[Display(Name = "Password")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "Password required")]
public string Password { get; set; }
[Display(Name = "Confirm new password")]
[Required(ErrorMessage = "Enter Confirm Password")]
[Compare ("Password", ErrorMessage = "The password and confirmation password do not match.")]
[DataType(DataType.Password)]
public string confirm_password { get; set; }
}
}
Index.cshtml:-
@model MvcNew.Models.Index
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Index</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
@Html.LabelFor(model => model. confirm_password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model. confirm_password)
@Html.ValidationMessageFor(model => model. confirm_password)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Index</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
@Html.LabelFor(model => model. confirm_password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model. confirm_password)
@Html.ValidationMessageFor(model => model. confirm_password)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
HomeController.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcNew.Models;
namespace MvcNew.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcNew.Models;
namespace MvcNew.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
0 comments:
Post a Comment