代码之家  ›  专栏  ›  技术社区  ›  Ali Jamal

无法在表中为标识列插入显式值

  •  1
  • Ali Jamal  · 技术社区  · 10 年前

    萨拉蒙·阿莱库姆 我在中变为NULL file 在FORM中发布文件后的操作实例

     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" />
    }
    

    我应该怎么做才能获得价值 文件 动作参数。我需要这方面的指导

    非常感谢。

    1 回复  |  直到 10 年前
        1
  •  4
  •   Moe    10 年前

    你的问题和问题的主题完全不同。这令人困惑。

    如果将文件传递给控制器时遇到问题,则输入文件名应与控制器方法中的参数匹配。 改变 <input type="file" name="Image" /> to <input type="file" name="file" />

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

    public ActionResult CreateDoctorProfile(HttpPostedFileBase Image){}
    

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

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