I have a view which shows files from folder and the number of files may vary from user to user
I am dynamically creating checkbox and capturing its values based on filename for each row
the code is as follows
My controller is as follows this passes value to view
var getinfo = await _context.EmployeeBasicInformations.FindAsync(id);
ViewBag.empid = getinfo.EmployeeId;
var foldername = getinfo.EmployeeEmail;
string dirPath = Configuration["FolderPath:Document_Path"];
string path = Path.Combine(dirPath, foldername);
string[] folderpath = Directory.GetFiles(path);
List files = new List();
foreach (string folderpaths in folderpath)
{
files.Add(new EmpDoc
{
Filename = Path.GetFileName(folderpaths),
EmployeeId = getinfo.EmployeeId,
}) ;
}
return View(files);MyModel is as follows
public int EmployeeId { get; set; }
public string? Form1{ get; set; }
public string? Form2 { get; set; }
public string? EnteredBy { get; set; }
public DateTime? EnteredDatetime { get; set; }
public string? UpdatedBy { get; set; }
public DateTime? UpdatedDatetime { get; set; }
public string? ValidatedBy { get; set; }
public string? Form3 { get; set; }
public string? Form4 { get; set; }
public string? Form5 { get; set; }
[NotMapped]
public IFormFile File { get; set; }
[NotMapped]
public string Filename { get; set; }
[NotMapped]
public string Filevalues { get; set; }the files are stored as form1.pdf, form2.pdf
when i check a checkbox for example if i am checking form1 checkbox , in db under form1 column i am saving it as 1 and 0 for non checked .
I am able to save the data, but i am facing issue when i relogin the page , i am unable to retrieve the values and pass it to view
my view is as follows
@foreach (handbook.Data.EmpDoc files in Model)
{
@if (files.Filevalues == "1")
{
@files.Filename
@Html.ActionLink("Download", "DownloadFile", new { fileName = files.Filename, id = files.EmployeeId })
}
else
{
@files.Filename
@Html.ActionLink("Download", "DownloadFile", new { fileName = files.Filename, id = files.EmployeeId })
}
}
Vishal JoshiRank #377 · 6.7K reputationPosted Feb 14, 2023, 11:50 PM EST
Hello
You need to change view code. need to set dabatase value to checkbox value attribute. please try the below code.
Thanks
kaushik guruRank #8,900 · 214 reputationPosted Feb 15, 2023, 12:11 AM EST
@vishal Joshi .. But how to populate all the checkbox value into is isdbchecked attribute
Jignesh KumarRank #91 · 22.9K reputationPosted Feb 16, 2023, 12:10 AM EST
@foreach (handbook.Data.EmpDoc files in Model) { @if (files.Filevalues == "1") { @files.Filename @Html.ActionLink("Download", "DownloadFile", new { fileName = files.Filename, id = files.EmployeeId }) } else { @files.Filename @Html.ActionLink("Download", "DownloadFile", new { fileName = files.Filename, id = files.EmployeeId }) } }