Hi friends, in this article I will explain about How to create a DropDownList field for MVC4 Razor view?
I already explained in the previous articles about Mvc 4 Razor CRUD Operation using C# || ASP.NET MVC 4 application to Create/Insert,Read,Update,Delete and Search functionality using Razor view engine and Entity Framework, How to Create Simple Login Page/Form in ASP.NET using MVC 4 and Enhancing WebGrid with Insert Update and Delete Operations Using Repository Pattern with Entity Framework in ASP.NET MVC 4 Razor
Compare.cshtml View
@model MvcNew.Models.Compare @{ ViewBag.Title = "Compare"; } <h2>Compare</h2> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>Compare</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.c_pwd) </div> <div class="editor-field"> @Html.EditorFor(model => model.c_pwd) @Html.ValidationMessageFor(model => model.c_pwd) </div> <p> <input type="submit" value="Create" /> </p> </fieldset> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |
Campare.cs Model
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using CompareAttribute = System.Web.Mvc.CompareAttribute; namespace MvcNew.Models { public class Compare { [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 c_pwd { get; set; } } } |
HomeController.cs Controller
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 Compare() { return View(); } } } |
The output of the above code as shown in the below figure.
Very useful approach. Thank You!
ReplyDeleteVery Nice all the best
ReplyDeleteThank you for sharing this ASP.NET MVC4 development tutorial
ReplyDeleteVery Nice
ReplyDelete