TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
zeeshan akram
1.4k
325
18k
Upload multiple Images but store in Database only one!
Feb 22 2020 2:36 AM
How to upload multiple images?
Hi, I want to upload multiple images in the database base, I select the multiple-image and then upload button but insert in the database only 1 image, any expert can you tell me where I am wrong.
Image Model
public
partial
class
Image
{
public
int
imgID {
get
;
set
; }
public
string
ImgPath {
get
;
set
; }
public
long
ProdID {
get
;
set
; }
public
virtual
Product Product {
get
;
set
; }
}
Controler
public
ActionResult AddNewProducts(ProductViewModel prod, List
file)
{
try
{
List
PTlist = _IproductType.PTList();
ViewBag.Ptlist =
new
SelectList(PTlist,
"PType_ID"
,
"P_Name"
);
//Product Color List
List
pColorList = _IProductColor.PColorlist();
ViewBag.pColor_List =
new
SelectList(pColorList,
"C_ID"
,
"C_Name_OR_Code"
);
List
pSizeList = _ISize.pSizeList();
ViewBag.pSizeLists =
new
SelectList(pSizeList,
"S_ID"
,
"S_Size"
);
string
PathDB =
string
.Empty;
Image img =
new
Image();
foreach
(HttpPostedFileBase files
in
file)
{
string
filename = Path.GetFileName(files.FileName);
string
_filename = DateTime.Now.ToString(
"yymmssff"
) + filename;
string
extension = Path.GetExtension(files.FileName);
string
path = Path.Combine(Server.MapPath(
"~/Upload/"
), _filename);
PathDB =
"~/Upload/"
+ _filename;
if
(extension.ToLower() ==
".jpeg"
|| extension.ToLower() ==
".jpg"
|| extension.ToLower() ==
".png"
)
{
if
(files.ContentLength <= 1000000)
{
img =
new
Image();
img.imgID = prod.ImgID;
img.ImgPath = PathDB;
img.ProdID = prod.ProductID;
}
else
ViewBag.sizemsg =
"Size Limit accessed "
;
}
else
ViewBag.fileformat =
"File is not Format is not Correct"
;
}
}
}
Reply
Answers (
1
)
Msg 443, Level 16, State 15, Invalid use of a side-effecting
please share example or project mvc.net EF code first