我有一个6行的表,每行有2列(文件标题和附件文件)。
HTML
表行如下所示:
<tr>
<td>1</td>
<td>
<input type="text" id="Attachment_Desc1" name="Job_Requests_Det[1].Attachment_Desc" uniqueid="1" class="form-control" required="">
</td>
<td>
<input type="file" id="Attachment_Path1" name="Job_Requests_Det[1].Attachment_File" class="file-styled" required="required">
</td>
</tr>
我想保存表记录,但是当我提交表单时,每次尝试编辑代码时,列表上只有一条记录
这是我在控制器上的代码:
public ActionResult Create([Bind(Include = "Job_Request_ID,Attachment_Desc,Attachment_Path")] Job_Requests job_Requests,
List<Job_Requests_Det> Job_Requests_Det)
{
if (Job_Requests_Det != null)
{
if (Job_Requests_Det.Count > 0)
{
for (int i = 0; i < Job_Requests_Det.Count; i++)
{
if (Job_Requests_Det[i].Attachment_Desc == null)
continue;
var requestDet = new Job_Requests_Det();
//requestDet.Job_Request_ID = job_Requests.Job_Request_ID;
requestDet.Attachment_Desc = Job_Requests_Det[i].Attachment_Desc;
if (Request.Files != null)
{
for (int x = 0; x < Request.Files.Count; x++)
{
HttpPostedFileBase f = Request.Files[x];
if (f.FileName == "")
continue;
string tmpf = Guid.NewGuid().ToString() + f.FileName;
string path = Path.Combine(Server.MapPath("~/UploadDir/Applicants/"), tmpf);
f.SaveAs(path);
requestDet.Attachment_Path = tmpf;
}
}
db.Job_Requests_Det.Add(requestDet);
}
}
}
int Rows = db.SaveChanges();//update
if (Rows == 0)
{
return Json("error", JsonRequestBehavior.AllowGet);
}
return View();
}
您能帮我找到错误吗?