Skip to main content
 首页 » 编程设计

c#之无法为表中的标识列插入显式值

2024年02月05日10arxive

萨拉蒙阿勒库姆 在 FORM 中发布文件后,我在 file 操作实例中获取 NULL

 public ActionResult CreateDoctorProfile(HttpPostedFileBase file) 
        { 
 
            int LoggedInPersonID = Convert.ToInt32(Session["LoggedInPersonId"]); 
            erx_t_personnel PersonnelInformation = db.erx_t_personnel.Where(PersonnelInformation1 => PersonnelInformation1.Person_Id == LoggedInPersonID).FirstOrDefault(); 
 
            return View(PersonnelInformation); 
        } 

这是我的看法

@model Doctors_Search_Engine.Models.erx_t_personnel 
 
@{ 
    ViewBag.Title = "Personnel Registration"; 
 
 
} 
 
<h2>Personnel Registration</h2> 
 
@using (Html.BeginForm()) 
{ 
    @Html.AntiForgeryToken() 
 
 
        <input type="file" name="file" /> 
        <input type="submit" value="Create" class="btn btn-default" /> 
} 

我应该怎么做才能在操作参数的文件 中获取值。我需要这方面的指导

谢谢

请您参考如下方法:

您遇到的问题和您的问题的主题完全不同。令人困惑。

如果您在将文件传递给 Controller ​​时遇到问题,那么您的输入文件名应该与 Controller 方法中的参数匹配。 更改 <input type="file" name="Image" /> to <input type="file" name="file" />

或者将您的操作结果更改为:

public ActionResult CreateDoctorProfile(HttpPostedFileBase Image){} 

您还需要为您的表单设置加密类型。

using (Html.BeginForm(new { enctype = "multipart/form-data" }))