PDA

View Full Version : خطلایIndex was out of range. Must be non-negative and less than the size of the collection. Paramete



RIG000
دوشنبه 13 آبان 1392, 08:44 صبح
این خطا رو تو این کدی که نوشتم میده

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

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.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

Line 30: { Line 31: ToranjEntities3 db = new ToranjEntities3(); Line 32: var uploadedFile = Request.Files[0]; Line 33: var fileName = Path.GetFileName(uploadedFile.FileName); Line 34: var fileSavePath = Server.MapPath("/Images/Laptop" + fileName);

اینم کل کد CREATE A RECORD ...

[HttpPost]
public ActionResult CreateLoptop( tblLaptopProduct Laptop )
{
ToranjEntities3 db = new ToranjEntities3();
var uploadedFile = Request.Files[0];
var fileName = Path.GetFileName(uploadedFile.FileName);
var fileSavePath = Server.MapPath("/Images/Laptop" + fileName);
uploadedFile.SaveAs(fileSavePath);
Laptop.ImageSrc = fileName;
db.tblLaptopProducts.Add(Laptop);
db.SaveChanges();
return View();
}

RIG000
دوشنبه 13 آبان 1392, 08:45 صبح
var uploadedFile = Request.Files[0];پ
اینو خطا میده...

RIG000
دوشنبه 13 آبان 1392, 09:03 صبح
در ضمن اینو چک کردم برابر با 0 بود

Request.Files.Count=0

RIG000
دوشنبه 13 آبان 1392, 09:13 صبح
مشکل از این بود .

@using (Html.BeginForm("CreateLoptop", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{

این بالایی الان درست هست ..

RIG000
دوشنبه 13 آبان 1392, 09:24 صبح
عکس رو لود نمیکنه؟!!!!

@Html.DisplayFor(modelItem => ("<img src='~/Images/" + item.ImageSrc + "' />"))

RIG000
دوشنبه 13 آبان 1392, 09:35 صبح
با این
<img src="@Url.Content(Model.ImagePath)" alt="Image" />
درست کار میکنه ولی عکس رو لود نمیکنه؟!!!! خود عکس رو نمیاره؟
قبلا هم با درستور url مشکل این چنینی داشتم

RIG000
دوشنبه 13 آبان 1392, 09:40 صبح
اینم اینجوری حل کردم... شاید یه روز کسی همچین مشکلایی داشت بتونه این شکلی حل کنه ..
:)

<img style="width:500px; height:500px" src="@Url.Content("~/Images/"+item.ImageSrc)" alt="Image" />