DropDownList returning wrong selected value.
The first two record are showing different dropdownlist selected records please help.
<div class="form-group">
@Html.LabelFor(model => model.CLASS, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.CLASS, ViewBag.CityList as SelectList, "--Select Class--", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CLASS, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.STREAM, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.STREAM, ViewBag.CityList3 as SelectList, "--Select Sex--", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.STREAM, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SEX, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.SEX, ViewBag.CityList2 as SelectList, "--Select Sex--", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.SEX, "", new { @class = "text-danger" })
</div>
</div>
below is my controller
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using UNIFORMMANAGER.Models;
namespace UNIFORMMANAGER.Controllers
{
public class STUDENTsController : Controller
{
private STOREEntities db = new STOREEntities();
private STOREEntities1 db2 = new STOREEntities1();
// GET: STUDENTs
public ActionResult Index()
{
return View(db.STUDENTs.ToList());
}
// GET: STUDENTs/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
STUDENT sTUDENT = db.STUDENTs.Find(id);
if (sTUDENT == null)
{
return HttpNotFound();
}
return View(sTUDENT);
}
// GET: STUDENTs/Create
public ActionResult Create()
{
List<Class> classlist = db.Classes.ToList();
ViewBag.CityList = new SelectList(classlist, "no", "Class1");
List<streamdata> classlist3 = db.streamdatas.ToList();
ViewBag.CityList3 = new SelectList(classlist3, "atk", "Stream");
List<Sexdata> classlist2 = db2.Sexdatas.ToList();
ViewBag.CityList2 = new SelectList(classlist2, "atk", "Sex");
return View();
}
// POST: STUDENTs/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "NAME,ACNOS,HOME,FATHER,MOTHER,NEXTOFKIN,HOMETEL,FATHERSJOB,FORMERSCHOOL,ADMDATE,BDATE,HOUSE,CLASS,STREAM,SEX,Photo,ADMNO,ACCOUNT,REPEAT,STATUS,STDTYPE,MATH,ENG,SCIENCE,SOCIAL,HISTORY,GEOG,LUG,REL,ACCT,COMM,ART,LIT,DIV,FRE,GER,ARAB,BIO,CHEM,PHY,HEALTH,AGR,HEALTHY,DATEDISMISSED,DATEABSCOND,DATECOMPLETED,tutor,autofield,missedexam,missedtest,MTCMK,MTCGRD,MTCPSN,ENGMK,ENGGRD,ENGPSN,SSTMK,SSTGRD,SSTPSN,SCIMK,SCIGRD,SCIPSN,TOTALMK,AGGR,POSN,engint,t296,t297,t298,t300,division,t301,t302,t303,missedb6,divisionb6,multipurposestatus,dda,parentac,parentbankcode,parentbankbranchcode,clearinghousecode,Parentbanktittle,indexno,t16,RELIGION,oldstream,CITIZENSHIP,POSITIONINFAMILY,LANGUAGE,HOMEADDRESS,VILLAGE,SUBCOUNTY,PARISH,DISTRICT,PRIMARYSCHOOL,PLEINDEXNO,PLERESULT,UCEINDEXNO,UCERESULT,Multipurposefield,avrg,t26,t36,t46,t56,t66,Changed,Classcontrol,Attendence,added,Username,Paydate,Rptno,mmobile,fmobile,Femail,Memail,Nkin,Rclass")] STUDENT sTUDENT)
{
if (ModelState.IsValid)
{
db.STUDENTs.Add(sTUDENT);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(sTUDENT);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}