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
selvi jp
NA
323
77.3k
i want add model data with mulitple image
May 8 2021 1:20 PM
i want add model data with mulitple image but model field are coming null how can i pass model data here
[HttpPost()]
public string UploadFiles()
{
int iUploadedCnt = 0;
// DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES.
string sPath = "";
sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/");
System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
// CHECK THE FILE COUNT.
for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
{
System.Web.HttpPostedFile hpf = hfc[iCnt];
if (hpf.ContentLength > 0)
{
// CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE)
if (!File.Exists(sPath + Path.GetFileName(hpf.FileName)))
{
// SAVE THE FILES IN THE FOLDER.
hpf.SaveAs(sPath + Path.GetFileName(hpf.FileName));
iUploadedCnt = iUploadedCnt + 1;
//Read the File data from Request.Form collection.
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
//Insert the File to Database Table.
WebApiDatabaseEntities entities = new WebApiDatabaseEntities();
ImageUpload file = new ImageUpload();
ImageUpload model = new ImageUpload();
file.Title = model.Title;
file.ImagePath = Path.GetFileName(hpf.FileName);
file.ImageType = hpf.ContentType;
file.CreatedDate = DateTime.Now;
entities.ImageUploads.Add(file);
entities.SaveChanges();
}
}
}
// RETURN A MESSAGE.
if (iUploadedCnt > 0)
{
return iUploadedCnt + " Files Uploaded Successfully";
}
else
{
return "Upload Failed";
}
}
Reply
Answers (
0
)
Effective Paging in a Gridview From a Stored Procedure
ASP.NET Entry level job