Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

This blog incorporates articles about ASP.Net 3.5 and 4.0. Also good amount of concentration is laid on .net projects,book reviews,C# articles,jobs in present industry and some general topics.
Browse by Tags · View All
ARTICLE 61
SQL Server 31
TSQL 30
C# 16
ASP.Net 11
JumpStart 8
GENERAL 8
ASP.Net MVC 7
C# 4.0 6
ASP.Net 4.5 5

Archive · View All
December 2012 22
July 2012 12
May 2012 8
January 2013 7
April 2013 4
March 2013 4
February 2013 4
January 2012 4
August 2012 2
May 2013 1

Rami Vemula's Blog

Dropdownlist Validation in ASP.Net MVC 3–Razor

May 12 2012 12:00AM by rami   

 

In this short tutorial, I am going to show how to validate a Dropdownlist in MVC3 using Razor Syntax.

Our Model Class –

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace DropdownListValidation.Models
{
    public class DropdownListModel
    {

        [Required( ErrorMessage = "Selection is a MUST" )]
        public string SelectedItem { get; set; }

        private List<string> _items;
        public List<string> Items
        {
            get
            {
                _items = new List<string>();
                _items.Add("One");
                _items.Add("Two");
                _items.Add("Three");
                return _items;
            }
        }
    }
}

 

Our Controller Class –

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DropdownListValidation.Models;

namespace DropdownListValidation.Controllers
{
    public class HomeController : Controller
    {
        //Render Action
        [HttpGet]
        public ViewResult Index()
        {
            DropdownListModel model = new DropdownListModel();
            return View(model);
        }

        //Process Action
        [HttpPost]
        public ViewResult Index(DropdownListModel model)
        {
            //TODO: Validate using if(ModelState.IsValid) and process information
            return View(model);
        }
    }
}

Our View –

@model DropdownListValidation.Models.DropdownListModel

@{
    Layout = null;
}

<!DOCTYPE html>
<link rel="stylesheet" href="@Href("~/Content/Site.css")" type="text/css" />

<html>
<head>
    <title>Index</title>
</head>
<body>
    <div>
        <!--Render the DropDownListmodel -->
        @using (Html.BeginForm())
        {
            <p>@Html.ValidationSummary()</p>
            <p>Select an Item : @Html.DropDownListFor(x => x.SelectedItem, new SelectList(Model.Items), "--Choose any Item--" )</p>
            <input type="submit" value="Submit" />
        }

        <!-- Display Selected Item -->
         @if (!String.IsNullOrWhiteSpace(Model.SelectedItem))
         {
              <span>Selected Item : @Model.SelectedItem</span>
         }

    </div>
</body>
</html>

When you click on submit button, without selecting any value from Dropdownlist –

MVC3-RAZOR-DDL-Validation1

When we select an item and click on submit button –

MVC3-RAZOR-DDL-Validation2


Republished from Rami Vemula [15 clicks].  Read the original version here [5 clicks].

rami
525 · 0% · 70
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Dropdownlist Validation in ASP.Net MVC 3–Razor" rated 5 out of 5 by 2 readers
Dropdownlist Validation in ASP.Net MVC 3–Razor , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]