smc develpments

smc develpments

  • NA
  • 121
  • 1.3k

Saving more than 1 attachment to database from partial view

Sep 6 2021 10:51 AM

I'm not sure this explanation is easy to understand but I will do my best.

I have one table which holds the main details.

One table for saving sub details.

One for saving attachment images and related details.

So views go as,

Main view for main details.

Partial view for sub details.

Partial view for Attachment details.

Details pass to the database correctly other than the attachments.

So If I Click Add it will generate another item list and I can attach another image.

After all, So when I click the send button All the details will be saved to the database but attachments not showing there.

Here is the Controller,

if (appRequest.Purchase!=null){appRequest.Purchase = new List() {new Purchase{PurchasingEmpl = appRequest.PurchasingEmpList,PurchasingItems = appRequest.PurchasingItemsList}};
appRequest.Create_By = int.Parse(((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("UserId").Value);
appRequest.Created_Date = DateTime.Now;
appRequest.Modified_By = int.Parse(((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("UserId").Value);
appRequest.Modified_Date = DateTime.Now;
appRequest.Status = true;
appRequest.Approval_Status = 1;
db.AppRequest.Add(appRequest);
db.SaveChanges();

PurchasingItemsList is an IList created on the Model.

[NotMapped]
public IList PurchasingItemsList { get; set; }

And this is the sub class

public class PurchasingItems{[Key]public int Id { get; set; }[Required][ForeignKey("Purchase")]public int Purchase_Id { get; set; }public virtual Purchase Purchase { get; set; }public int Supp_Id { get; set; }public int Itm_Description_Id { get; set; }public decimal Unit_Amount { get; set; }public byte[] Attachment { get; set; }public decimal Qty { get; set; }public string Recomandation { get; set; }public bool Status { get; set; }public bool Settled { get; set; } = false;public string PoNo { get; set; }}

So my issue is, when I click send button, all the details will pass to the data tables other than attachments. Need to know a way to upload the attachment also to the data table.Hope my problem is clearly described. Thank you

Here are the data table views


Answers (3)