2014-06-15 1 views
0

gars Ho .Je essayer d'obtenir 3 photos de l'utilisateur donc mon modèle i quelque chose comme ceci:HttpPostedFileBase retourne null à mon contrôleur

namespace DomainClass 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.Web.Http; 
    public partial class CompanyMember 
    { 
     public CompanyMember() 
     { 
      this.Proficiencies = new HashSet<Proficiency>(); 
     } 

     [DisplayName(" شناسه")] 
     public int Id { get; set; } 

     [DisplayName("عکس")] 
     public string ImageUrl { get; set; } 

     [DisplayName("کارت ملی")] 
     public string IntCartCopy { get; set; } 

     [DisplayName("شناسنامه")] 
     public string IdentityCartCopy { get; set; } 

       [System.ComponentModel.DataAnnotations.Schema.NotMapped] 
     public HttpPostedFileBase ImgFileImageUrl { get; set; } 
       [System.ComponentModel.DataAnnotations.Schema.NotMapped] 

     public HttpPostedFileBase ImgFileIntCartCopy { get; set; } 
       [System.ComponentModel.DataAnnotations.Schema.NotMapped] 

     public HttpPostedFileBase ImgFileIdentityCartCopy { get; set; } 


     public virtual Company Company { get; set; } 
     public virtual ICollection<Proficiency> Proficiencies { get; set; } 
    } 

donc à mon avis pour obtenir l'image que je crée 3 balises d'entrée comme celui-ci :

@model DomainClass.CompanyMember 

@{ 
    ViewBag.Title = "اضافه کردن اعضاء"; 
} 
@using (Html.BeginForm("Create", "CompanyMember", FormMethod.Post, 
    new { id = "form", enctype = "multipart/form-data" })) 
{ 
    @Html.ValidationSummary(true) 
    <div class="wrapper-left"> 
     <div class="wrapper-top-addCompany"> 
      اعضاء 
      <div style="float: left; padding-left: 20px;"> 
       <div class="divider"></div> 
       <div class="buttonPossion"> 
        <input type="submit" value="ذخیره اطلاعات" Class="buttonSave" /> 
        @Html.ActionLink("بازگشت", "index", new {companyId = ViewBag.companyId}, new {@class = "buttonBlueLink"}) 
       </div> 
       <div class="divider"></div> 
      </div> 
     </div> 
          @Html.HiddenFor(model => model.CompanyId) 

     <div class="wrapper"> 
      <div class="wrapper-Member" style="padding-bottom: 30px; margin-bottom: 5px; width: 98%"> 
       <h2> 
        اضافه کردن اعضاء جدید 
       </h2><br/><br/><br/> 
       <div class="editor-label"> 
        @Html.LabelFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Name) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Family) @Html.ValidationMessageFor(model => model.Family) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Family) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.EducationLevel) @Html.ValidationMessageFor(model => model.EducationLevel) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.EducationLevel) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.University) @Html.ValidationMessageFor(model => model.University) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.University) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Mobile) @Html.ValidationMessageFor(model => model.Mobile) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Mobile) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Telephone) @Html.ValidationMessageFor(model => model.Telephone) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Telephone) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Address) @Html.ValidationMessageFor(model => model.Address) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Address) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Email) @Html.ValidationMessageFor(model => model.Email) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Email) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.InternationalCode) @Html.ValidationMessageFor(model => model.InternationalCode) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.InternationalCode) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Field) @Html.ValidationMessageFor(model => model.Field) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Field) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Job) @Html.ValidationMessageFor(model => model.Job) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Job) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Share) @Html.ValidationMessageFor(model => model.Share) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Share) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.Password) @Html.ValidationMessageFor(model => model.Password) 
       </div> 
       <div class="editor-field"> 
        @Html.EditorFor(model => model.Password) 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.ImageUrl) 
       </div> 
       <div class="editor-field"> 
        @Html.HiddenFor(model => model.ImageUrl) 
        <input id="imgProfile" type="file" name="ImgFileImageUrl"/> 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.IntCartCopy) 
       </div> 
       <div class="editor-field"> 
        @Html.HiddenFor(model => model.IntCartCopy) 
        <input id="imgIntCartCopy" type="file" name="ImgFileIntCartCopy"/> 
       </div> 

       <div class="editor-label"> 
        @Html.LabelFor(model => model.IdentityCartCopy) 
       </div> 
       <div class="editor-field"> 
        @Html.HiddenFor(model => model.IdentityCartCopy) 
        <input id="imgIdentityCartCopy" type="file" name="ImgFileIdentityCartCopy"/> 
       </div> 

      </div> 
     </div> 
    </div> 
} 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

@section Scripts { 
    @Scripts.Render("~/bundles/jqueryval") 
} 

mais après avoir soumis les 3 HttpPostedFileBase colums return null .in mon contrôleur i vérifié la valeur du fichier et tous sont nuls pourquoi et mon état si les rendements faux

?
public ActionResult Create(CompanyMember companyMember) 
     { 
      if (companyMember.ImgFileImageUrl != null && companyMember.ImgFileIntCartCopy!=null && companyMember.ImgFileIdentityCartCopy!=null) 
      { 

       saving 
      } 

     } 

Meilleures salutations

+1

Affichez votre vue complète avec le formulaire –

Répondre

-1

fichiers Publié sont disponibles dans

Request.Files 

Vous devriez les lire et enregistrer la db par l'action du contrôleur. Pour ce faire, utilisez le nom d'entrée en tant qu'index de la table Request.Files, par exemple:

HttpPostedFileBase img = Request.Files["ImgFileIntCartCopy"]; 
if(img != null) 
    img.SaveAs(path + img.FileName);