8 Şubat 2013 Cuma

Automapper - Index was outside the bounds of the array


Index was outside the bounds of the array.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

 
Automapper'de map işlemi sırasında yukarıdaki gibi bir hata olıuşursa
Source veya Destination nesnesinde tanımlı byte [] dizisine byte [0] şeklinde bir atama yapılmıştır.

Çözüm:  byte[0] değeri  içermedeğini kontrol et.




14 Ocak 2013 Pazartesi

Asp.Net MVC3 Value Cannot Be Null Hatası

MVC3'de  dropdown kontrolüne viewbag ile taşınan liste, post işlemi sırasında
value cannot be null, paramater name: items

Oluşan hata:

Line 27:         </div>
Line 28:         <div class="editor-field">
Line 29:   @Html.DropDownListFor(Model => Model.carId,

new SelectList(ViewBag.Cars as System.Collections.IEnumerable, "CarId", "CarName"),
Line 30:             "Select a Car", new { id = "ddlCars" })
Line 31:         </div>

yukarıda görüldüğü gibi,  post işlemi yapılır yapılmaz hataya düşüyor.

Çözüm:
  http://stackoverflow.com/questions/5207355/dropdownlist-items-null-when-posting-to-edit-form

adresinden de görüleceği üzere,

ilgili action'da dönen değer view'da görüntülenmeden önce liste bir kez daha doldurulmalı.

 [HttpPost]
        public ActionResult Add(ViewModelKart kart)
        {
            if (ModelState.IsValid)
            {
                return RedirectToAction("Index""Home");
            } 
            ViewBag.Cars = db.GetCarList();
 
            return View(kart);
        }