Click here to Skip to main content
15,892,005 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Developing an election ballot box app. Pin
samflex28-Apr-16 9:59
samflex28-Apr-16 9:59 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming28-Apr-16 11:03
mveRichard Deeming28-Apr-16 11:03 
GeneralRe: Developing an election ballot box app. Pin
samflex28-Apr-16 11:58
samflex28-Apr-16 11:58 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming29-Apr-16 2:04
mveRichard Deeming29-Apr-16 2:04 
GeneralRe: Developing an election ballot box app (SOLVED). Pin
samflex2-May-16 3:22
samflex2-May-16 3:22 
QuestionUpdate progressbar with wcf webservice Pin
Member 1247474222-Apr-16 1:05
Member 1247474222-Apr-16 1:05 
SuggestionRe: Update progressbar with wcf webservice Pin
Richard Deeming22-Apr-16 1:15
mveRichard Deeming22-Apr-16 1:15 
Questionpls Help me..binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city.. Pin
sunil321-Apr-16 0:28
sunil321-Apr-16 0:28 
hello...pls help me im beginner in mvc ...working in MVC4..
 binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city..

i want to show  country's related   State..and that state's related all City..pls help..what i want to do..

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcDdlStudCRUD.Models;

namespace MvcDdlStudCRUD.Controllers
{
    public class HomeController : Controller
    {
        private WorkTraningEntities db = new WorkTraningEntities();

        //
        // GET: /Home/

        public ActionResult Index()
        {
            var students = db.Students.Include(s => s.City).Include(s => s.Country).Include(s => s.State);
            return View(students.ToList());
        }

        //
        // GET: /Home/Details/5

        public ActionResult Details(int id = 0)
        {
            Student student = db.Students.Find(id);
            if (student == null)
            {
                return HttpNotFound();
            }
            return View(student);
        }

        //
        // GET: /Home/Create

        public ActionResult Create()
        {

            ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName");
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName");
            ViewBag.StateID = new SelectList(db.States, "StateID", "StateName");
            return View();
        }

        //
        // POST: /Home/Create

        [HttpPost]
        public ActionResult Create(Student student)
        {

            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
            ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
            return View(student);
        }
        public JsonResult SelectStates(int id)
        {
            IEnumerable<State> states = db.States.Where(stat => stat.CountryID == id);
            return Json(states);
        }

        //
        // GET: /Home/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Student student = db.Students.Find(id);
            if (student == null)
            {
                return HttpNotFound();
            }
            ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
            ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
            return View(student);
        }

        //
        // POST: /Home/Edit/5

        [HttpPost]
        public ActionResult Edit(Student student)
        {
            if (ModelState.IsValid)
            {
                db.Entry(student).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.CityID = new SelectList(db.Cities, "CityID", "CityName", student.CityID);
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", student.CountryID);
            ViewBag.StateID = new SelectList(db.States, "StateID", "StateName", student.StateID);
            return View(student);
        }

        //
        // GET: /Home/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Student student = db.Students.Find(id);
            if (student == null)
            {
                return HttpNotFound();
            }
            return View(student);
        }

        //
        // POST: /Home/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Student student = db.Students.Find(id);
            db.Students.Remove(student);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}

‹ Previous Thread|Next Thread ›
Microsoft Ad
AnswerRe: pls Help me..binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city.. Pin
John C Rayan21-Apr-16 0:55
professionalJohn C Rayan21-Apr-16 0:55 
Questionc# Image Processing from byte[] to image, centering the image on a square canvas Pin
jkirkerx20-Apr-16 13:47
professionaljkirkerx20-Apr-16 13:47 
AnswerRe: c# Image Processing from byte[] to image, centering the image on a square canvas Pin
Richard Deeming21-Apr-16 2:40
mveRichard Deeming21-Apr-16 2:40 
GeneralRe: c# Image Processing from byte[] to image, centering the image on a square canvas [solved] Pin
jkirkerx21-Apr-16 9:09
professionaljkirkerx21-Apr-16 9:09 
QuestionPls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
sunil319-Apr-16 21:37
sunil319-Apr-16 21:37 
AnswerRe: Pls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
Nathan Minier20-Apr-16 1:53
professionalNathan Minier20-Apr-16 1:53 
GeneralRe: Pls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
sunil321-Apr-16 0:26
sunil321-Apr-16 0:26 
AnswerRe: Pls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
John C Rayan20-Apr-16 2:38
professionalJohn C Rayan20-Apr-16 2:38 
GeneralRe: Pls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
sunil321-Apr-16 0:25
sunil321-Apr-16 0:25 
GeneralRe: Pls help getting error..The name 'ObjectFactory' does not exist in the current context Pin
John C Rayan21-Apr-16 0:32
professionalJohn C Rayan21-Apr-16 0:32 
QuestionFreezing Heading of one DataGrid with data from different datasets Pin
Member 1247018419-Apr-16 20:34
Member 1247018419-Apr-16 20:34 
QuestionHow to use HandleUnknownAction Pin
nasirs516-Apr-16 23:13
nasirs516-Apr-16 23:13 
AnswerRe: How to use HandleUnknownAction Pin
John C Rayan17-Apr-16 23:24
professionalJohn C Rayan17-Apr-16 23:24 
QuestionMVC asp.net 4.0 "using templates" Pin
Member 1241562115-Apr-16 1:52
Member 1241562115-Apr-16 1:52 
AnswerRe: MVC asp.net 4.0 "using templates" Pin
John C Rayan15-Apr-16 2:00
professionalJohn C Rayan15-Apr-16 2:00 
AnswerRe: MVC asp.net 4.0 "using templates" Pin
John C Rayan15-Jun-16 1:28
professionalJohn C Rayan15-Jun-16 1:28 
Questionworking in MVC4 ..Getting Error pls help Pin
sunil314-Apr-16 19:35
sunil314-Apr-16 19:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.