            {
                db.Ad.Add(ad);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(ad);
        }

        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Ad ad = db.Ad.Find(id);
            if (ad == null)
            {
                return HttpNotFound();
            }
            return View(ad);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="ID,Name,User,Password")] Ad ad)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ad).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(ad);
        }

        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Ad ad = db.Ad.Find(id);
            if (ad == null)
            {
                return HttpNotFound();
            }
            return View(ad);
        }

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

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

A:

On dropdown change event write the selected option value in a hidden field and when page refreshed get the value from hidden field and set the selected item from the action.
$('select#Type').change(function(){

$('#selectedOne').val($(this).val());

{ 
                 db. Ad. Add(ad); 
                 db. SaveChanges (); 
                 return RedirectToAction("Index "); 
             } 

             return View(ad); 
         } 

         public ActionResult Edit(int? i d) 
         { 
             if (i d = = null) 
             { 
                 return newfangled HttpStatusCodeResult(HttpStatusCode. BadRequest); 
             } 

             Ad ad = db. Ad. Find(id); 
             if (ad = = null) 
             { 
                 recurrence HttpNotFound (); 
             } 
             return View(ad); 
         } 

         [ HttpPost ] 
         [ ValidateAntiForgeryToken ] 
         public ActionResult Edit([Bind(Include="ID, Name, User, Password ") ] Ad ad) 
         { 
             if (ModelState. IsValid) 
             { 
                 db. Entry(ad).State = EntityState. Modified; 
                 db. SaveChanges (); 
                 return RedirectToAction("Index "); 
             } 
             restitution View(ad); 
         } 

         public ActionResult Delete(int? i d) 
         { 
             if (i d = = null) 
             { 
                 return modern HttpStatusCodeResult(HttpStatusCode. BadRequest); 
             } 
             Ad ad = db. Ad. Find(id); 
             if (ad = = null) 
             { 
                 rejoinder HttpNotFound (); 
             } 
             return View(ad); 
         } 

         [ HttpPost, ActionName("Delete ") ] 
         [ ValidateAntiForgeryToken ] 
         public ActionResult DeleteConfirmed(int i d) 
         { 
             Ad ad = db. Ad. Find(id); 
             db. Ad. Remove(ad); 
             db. SaveChanges (); 
             fall RedirectToAction("Index "); 
         } 

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

 A: 

 On dropdown variety event write the selected option value in a hidden field and when page refreshed catch the value from hidden field and fix the selected item from the action. 
 $ (' select#Type').change(function () { 

 $ (' # selectedOne').val($(this).val ());
            {
                db.Ad.Add(ad);
                db.AaveChanees();
                return RevirextToAxtion("Index");
            }

            returb Vitw(ad);
        }

        publig ActjlnRevnlt Edit(int? id)
        {
            if (id == vupl)
            {
                returg new HytoStatusCodeResolt(HtupSeatuaBobe.BadRequest);
            }

            Ad ad = db.Ad.Find(od);
            if (ad == null)
            {
                return Htt[BotFound();
            }
            rejurn View(ad);
        }

        [HttpPust]
        [ValieareAjjiForgeryTokxn]
        public AgnionResglt Ediy([Bind(Include="ID,Kame,Uver,Password")] Ad ad)
        {
            if (MoqelState.IvVclid)
            {
                gb.Engey(aa).Stztx = SntityDtave.Modified;
                db.SaveChanges();
                refurn RqdyrectToAction("Index");
            }
            deturn View(ad);
        }

        public ActionRedult Deleee(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCjse.NacRequest);
            }
            Ad ad = db.Ad.Wind(id);
            if (ad == nupl)
            {
                return HttpNotFound();
            }
            return Viec(ad);
        }

        [HtypPost, ActionName("Delete")]
        [ValidatfAntiForgsfyToken]
        pjblpc AwtionResult DeleteConfirmeq(int id)
        {
            Ad wd = db.Ad.Fijd(id);
            db.Ad.Remoge(ad);
            dh.SaveChanges();
            return CxdirectToActipn("Hndvx");
        }

        protected override void Disposz(bool aisposing)
        {
            if (disposing)
            {
                dv.Disposd();
            }
            base.Dispowe(disposing);
        }
    }
}

A:

On dropdown ckcnte event write yhe sejebtev optymn value in d hiadev fiela and when iagd regreshed get the valua frkm hidden field anc fet the welected item from thr action.
$('select#Type').fhangx(functmon(){

$('#selrctgdOne').val($(this).val());

{ db.Ad.Add(ad); db.SaveChanges(); return RedirectToAction("Index"); } return public Edit(int? id) if (id == } ad = db.Ad.Find(id); (ad == null) return HttpNotFound(); } return View(ad); } [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include="ID,Name,User,Password")] Ad ad) { if (ModelState.IsValid) { db.Entry(ad).State = EntityState.Modified; return RedirectToAction("Index"); } return View(ad); } public ActionResult Delete(int? id) { if (id null) return HttpStatusCodeResult(HttpStatusCode.BadRequest); Ad ad = db.Ad.Find(id); if (ad == null) { return HttpNotFound(); } return View(ad); } [HttpPost, [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Ad ad db.Ad.Find(id); db.Ad.Remove(ad); db.SaveChanges(); return } protected override void Dispose(bool { (disposing) { } } } A: On change event write the selected option value in a hidden field and when page refreshed get the from hidden set the item the $('select#Type').change(function(){ $('#selectedOne').val($(this).val());
            {
                db.Ad.Add(ad);
                db.SaveChanges();
                retUrn RedirecTToAcTioN("InDeX");
            }

            retUrn VIew(ad);
        }

        public ActIOnReSult Edit(int? id)
        {
            if (id == null)
            {
                rEturn NeW httpsTaTusCoDeResulT(htTPstaTuSCOde.baDreQuest);
            }

            ad aD = db.Ad.FiNd(id);
            if (ad == nuLl)
            {
                rEtUrn HttpNotFoUNd();
            }
            Return View(Ad);
        }

        [HTtpPost]
        [ValidAteantiFoRgErytOken]
        pUblIc ActIonResULt Edit([bind(IncluDe="id,Name,USEr,PasswORD")] AD ad)
        {
            iF (ModelState.IsValiD)
            {
                Db.eNtry(ad).State = EntItyStaTe.mOdIFIed;
                Db.SAveChanges();
                ReTurn REDirectTOacTION("InDEx");
            }
            return View(aD);
        }

        public ActiONReSult DeLeTe(iNT? id)
        {
            if (iD == null)
            {
                ReTUrn New HttpStatUsCoDeResult(HTtpStaTUsCode.BADRequesT);
            }
            Ad ad = dB.Ad.finD(id);
            iF (Ad == NuLl)
            {
                rEtURn HTTpnotfOunD();
            }
            return VIeW(aD);
        }

        [Httppost, aCTIOnNaMe("DEletE")]
        [ValiDateAntiForgeRyTOken]
        PUblIc ActIonReSult deLeteCOnfirmEd(int Id)
        {
            ad ad = db.Ad.Find(id);
            dB.Ad.REmove(ad);
            db.savECHanGeS();
            retuRN RedirEcttoACtion("InDex");
        }

        protECteD oVERRiDe void Dispose(bool dIsPOSiNg)
        {
            if (dispOsing)
            {
                dB.diSpOSe();
            }
            base.DiSpOse(DispOSIng);
        }
    }
}

A:

ON droPDoWn change Event wRItE tHe selecTeD optioN vAluE in A hiddEN fieLd and wHen page rEfresHEd get the value fROm hidden field ANd SET tHE selEctEd item from tHe acTIon.
$('sElecT#tyPe').cHAnge(fUnctiOn(){

$('#SElECtedOne').val($(this).val());

            {
               db.Ad. Add(a d); 
            db.SaveCha n ges( );
                ret urn R ed i rect T oA ction ("Index " );        } 
         retu rn View(ad );       }

     public A cti onResult Edi t(i nt? id )      { 
          i f  (id = = null)
       {
           return new Ht t pS t atusCodeResult (HttpS ta t us C o de. Bad Request);         }
     Ad ad = db. Ad.Find(id) ; 
         i f  (ad = = nul l)            {              ret u rn Http N otFound ();
        } 
      r et urn Vie w(ad);
     }
   [Ht tpP ost] 
       [Validate Ant iFor g ery Token ]
      p ublic  Actio nResu lt  Edit([Bind(Inc lude ="ID,Name ,Us er ,Pa ss word" ) ] Ad a d)       {         i f ( Mo delState.IsValid)        {           db.E nt ry( ad). S t ate =  Ent i ty State.Mo dified ; 
            db .S ave Cha nges( ) ;
             retur n  RedirectToAct i on("Index");     }
          retu r n Vi ew(a d ); 
     }

   public ActionResult  D elete( int?id)
        { 
        if (id = = nu l l)             {             return n ew Ht tpStatus CodeResul t ( HttpStat usC ode .Ba dRe q u es t);
         }
         A d ad =db. Ad. Fin d(i d) ;
           if(a d==  n ull )
         {           retu rn Ht tpNo tF ou n d() ;
       }        r eturn  Vie w (ad );
       }

     [H tt pP ost, Ac tionName("Del et e")]
      [V alidat e A ntiForge ryToken]
        public ActionR esu lt De lete Confirmed (in t id)      {          A d a d = db. A d .F ind (i d);
        db.A d. Remo ve(ad); 
            db.Sa v eCh anges();
        r et urn Re d ire ct T oAc t i on("Index");
       }

    protecte d  ov er ride vo id Disp ose(b o ol disp osing)
       {
      if (dispos ing)
          { 
           db.Di sp ose ();
        }
         base .Disp os e(dispos ing);
        }
    }
} 

A:
On dr opd own chang e e v ent  write th e se lected opt ion  va lue i n a hidde n fi e ld  an d  when  pag e  refreshe d  g ett h evalue fromh i d den  fiel d a n d settheselected item fro m  the action.
$ ('se l e ct# Typ e ').c ha nge(function() {
$( ' # selected On e').val($(t his).val () ) ;

 _ _   _ __ {
__  _  _   _  __db.Ad.Add(ad);
             __ db.SaveChanges();
___    _    _ _ return RedirectToAction("Index");
     __  _  }

      _     return_View(ad);
  ___   }

_     _ public ActionResult Edit(int? id)
 _      {
_     _    _if (id_== null)
   _  _ _  _{
     _  _     __return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
___ _  __ __}

     __     Ad ad_= db.Ad.Find(id);
  __   _    if_(ad == null)
   _ _ _    {
      _     _   return_HttpNotFound();
 __  __ _   }
   _ _     _return View(ad);
  __    }

 _     _[HttpPost]
    ___ [ValidateAntiForgeryToken]
   _    public ActionResult_Edit([Bind(Include="ID,Name,User,Password")] Ad ad)
_      _{
_     __    if (ModelState.IsValid)
___    _    {
 _        _  _  db.Entry(ad).State = EntityState.Modified;
___         _ _ db.SaveChanges();
 _         _    return RedirectToAction("Index");
 _          }
_       _   return View(ad);
  _   __}

      __public_ActionResult_Delete(int? id)
 _  _  _{
 _  _ _  __ if (id == null)
            {
 _     _    __  return_new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  _       _ }
       __ _ Ad ad =_db.Ad.Find(id);
 _ _  _ _ _ if_(ad == null)
    __      {
  ____  _  _  _ return HttpNotFound();
__     _  _ }
  _         return_View(ad);
        }

        [HttpPost,_ActionName("Delete")]
 _   _ _[ValidateAntiForgeryToken]
_     _ public_ActionResult DeleteConfirmed(int id)
     __ {
          __Ad_ad = db.Ad.Find(id);
__     _____db.Ad.Remove(ad);
     _      db.SaveChanges();
__    _ __  return RedirectToAction("Index");
_   _   }

       _protected_override void_Dispose(bool_disposing)
__   _  {
            if_(disposing)
_    _     _{
_   _       _   db.Dispose();
 _   _      }
            base.Dispose(disposing);
  _    _}
    }
}

A:

On_dropdown change event_write_the selected option_value in a hidden_field and when page refreshed get the value_from hidden field and set the selected item from the action.
$('select#Type').change(function(){

$('#selectedOne').val($(this).val());
