MVC etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
MVC etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

1 Ekim 2018 Pazartesi

javascript ile dropdown secimine göre alan gösterimi


@Html.DropDownList("optionId", new SelectList(SelectListData), "Select an option")

@Html.TextBox("controlId")
<script>
  $("#optionId").on("change", function () {
    if ($("#optionId option:selected").index() == 0) {
      $("#controlId").hide();
    } else {
      $("#controlId").show();
    }
  });
</script>

2 Nisan 2014 Çarşamba

JavaScript MVC Örnek

Öncelikle Sayfamıza button ekliyoruz id'si "add-friend" olarak tanımlıyoruz. Daha sonra girilen verilerin gösterimin yapılacağı bir list tanımı yapıyoruz id'si "friends-list" atamasını yapıyoruz.

sayfamıza aşağıda yer alan jsicript kütüphanelerini ekliyoruz :
script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"
script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"
script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"


Javasipt Kodu :

(function ($) {
 
  Friend = Backbone.Model.extend({
    //Create a model to hold friend atribute
    name: null
  });
 
  Friends = Backbone.Collection.extend({
    //This is our Friends collection and holds our Friend models
    initialize: function (models, options) {
      this.bind("add", options.view.addFriendLi);
      //Listen for new additions to the collection and call a view function if so
    }
  });
 
  AppView = Backbone.View.extend({
    el: $("body"),
    initialize: function () {
      this.friends = new Friends( null, { view: this });
      //Create a friends collection when the view is initialized.
      //Pass it a reference to this view to create a connection between the two
    },
    events: {
      "click #add-friend":  "showPrompt",
    },
    showPrompt: function () {
      var friend_name = prompt("Who is your friend?");
      var friend_model = new Friend({ name: friend_name });
      //Add a new friend model to our friend collection
      this.friends.add( friend_model );
    },
    addFriendLi: function (model) {
      //The parameter passed is a reference to the model that was added
      $("#friends-list").append("
  • " + model.get('name') + "
  • ");
          //Use .get to receive attributes of the model
        }
      });
     
      var appview = new AppView;
    })(jQuery);

    5 Şubat 2014 Çarşamba

    MVC Notlar :

    Email Gönderim :
     //Basitce Mail atacak olan kodlarimizi yaziyoruz.
    SmtpClient client = new System.Net.Mail.SmtpClient ("mail.********.com.tr" , 25);
    NetworkCredential sifreBilgileri = new NetworkCredential ("****.****@**.com.tr" , "**@***" );
    
    
    client.Credentials = sifreBilgileri;
     
    string Mesaj = filterContext.Exception.Message;
    MailMessage mail = new MailMessage (
                         "ertugrul.kara@*********.com.tr" , //Kimden
                         "ertugrul.kara@*********.com.tr" , //Kime
                         "İçerik" , //Konu
                         "Konu :" + Mesaj //Mesaj icerigi
                         );
     
    client.Send(mail);

    MVC FileUpload ile Server Resim Dosyası kaydetmek / Klasör Kaydetmek

    Klasör varmı Kontrolu ve yoksa yeni Klasör oluşlturma:

    if (!Directory.Exists(Server.MapPath(@"~\images"))
                        {
                            Directory.CreateDirectory(Server.MapPath("../images"));
                        }


    Dosya Kaydetme :

    Form üzerindeki düzenlemeler : (enctype="multipart/form-data")

    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                        if (hpf.ContentLength == 0)
                        {
                            product.Resim = form["Resim1"];
                            continue;
                        }


                        if (!Directory.Exists(klasor))
                        {
                            Directory.CreateDirectory(klasor);
                        }
                        product.Resim = product.CategoryID + "/" + hpf.FileName;
                        hpf.SaveAs(Server.MapPath("../images/" + product.CategoryID) + "/" + hpf.FileName);

                    }

    31 Ocak 2014 Cuma

    C# MVC, Klasörde Bulunan Dosya adlarının DropDownList ile gösterimi

    C#'ta klasör ve dosya işlemlerinde System.IO kütüphanesini kullanırız.
    Örnek :

     Dosya Adlarının Çekilmesi :
     public List dosyalar(string path)
            {
    //DirectoryInfo tipinden bir değişken oluşturup,
    //içindeki dosyaları okumak istediğimiz klasörün dizin bilgisini veriyoruz.
                DirectoryInfo di = new DirectoryInfo(path);

    //FileInfo tipinden bir değişken oluşturuyoruz.
    //çünkü di.GetFiles methodu, bize FileInfo tipinden bir dizi dönüyor.
                FileInfo[] rgFiles = di.GetFiles();

    //Dosya İsimlerinin kayıt edilecegi List oluşturuyoruz
                List dosya = new List();

    //Foreach ile rgFiles içerisinde dönerek dosya adlarını listemize ekliyoruz
                foreach (FileInfo fi in rgFiles)
                {
    //fi.Name bize dosyanın adını dönüyor.

    //fi.FullName ise bize dosyasının dizin bilgisini döner.
                    dosya.Add(fi.Name);
                }

    //geriye liste olarak dosya isimlerinin bulunduğu string liste dönüyor
                return dosya;
            }

    // Action içerisinden çağırma ve ViewBag ile ViewBag atama kodu:
           List resim = dosyalar(Server.MapPath("~/images").ToString());
                   ViewBag.resimler = new SelectList(resim.AsEnumerable());


     //View İçeriği :
      @Html.DropDownList("Name",ViewBag.resimler as SelectList)