mvc replace space with dash - very simple sample.



** Ekran görüntüleri (screen shots)






 ** code behind (controller)
//AdıSoyadı  is FullName, KullaniciID is primary key fields....

[Route("Kullanicilar/xyz/{sKullaniciAdSoyadi}")]
public ActionResult Degistir(string sKullaniciAdSoyadi)
{
if (string.IsNullOrEmpty(sKullaniciAdSoyadi))
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
  //.........................................
//var sk = sKullaniciAdSoyadi.Replace(" ", "-");
var ks = sKullaniciAdSoyadi.Replace("-", " ");
  //.........................................
try
{
int sID = (from u in db.tbKullanicilar
where u.AdıSoyadı == ks
select u).FirstOrDefault().KullaniciID;

tbKullanicilar tbKullanicilar = db.tbKullanicilar.Find(sID);

if (tbKullanicilar == null)
{
return HttpNotFound();
}
  return View(tbKullanicilar);
  }
catch (Exception ex)
{
var ss = ex.Message;
throw;
}


}




Yorumlar