2013-03-20 2 views
0

인트라넷 응용 프로그램을 개발하기 위해 ASP.NET MVC4를 사용하고 있습니다. 주요 기능 중 하나는 사용자가 내 데이터베이스에 저장 될 파일을 업로드 할 수있게하는 것입니다. 이를 위해 jQuery를 사용하고 있습니다. 그러나, 나는 업로드 된 파일을 조작하기 위해 무엇을해야하는지 전혀 모른다. 나는 이미 콘트롤러 컨트롤러로 조작해야한다는 것을 이미 알고 있지만, 인터넷에서 몇 가지 팁을 읽은 후에는 어떻게해야하는지 알 수 없다. 나는 절대적으로 미리 만들어진 코드 샘플하지만 단지 방법은 진행하기를 요구하고 있지 않다MVC4가 업로드 한 파일을 가져옵니다.

@model BuSIMaterial.Models.ProductAllocationLog 
@{ 
    ViewBag.Title = "Create"; 
} 
<h2>Create</h2> 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 

    <fieldset> 
     <legend>ProductAllocationLog</legend> 
     <div class="editor-label"> 
      Date : 
     </div> 
     <div class="editor-field"> 
      @Html.TextBoxFor(model => model.Date, new { @class = "datepicker"}) 
      @Html.ValidationMessageFor(model => model.Date) 
     </div> 
     <div class="editor-label"> 
      Message : 
     </div> 
     <div class="editor-field"> 
      @Html.TextAreaFor(model => model.Message) 
      @Html.ValidationMessageFor(model => model.Message) 
     </div> 
     <div class="editor-label"> 
      Allocation : 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownList("Id_ProductAllocation", String.Empty) 
      @Html.ValidationMessageFor(model => model.Id_ProductAllocation) 
     </div> 
     <div class="demo" style="float:left; margin-top:5px;"> 

      <div id="aupload" style = "border:2px dashed #ddd; width:100px; height:100px; margin-right:10px; padding:10px; float:left;"></div> 
      <div id="uploaded" style = "border: 1px solid #ddd; width:550px; height:102px; padding:10px; float:left; overflow-y:auto;"></div> 

     </div> 
     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
} 
<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

:

여기 내이다. 그것은 매우 친절합니다.

답변

0

세 가지가 있습니다. 첫째로,보기에 이미지 업로드 필드를 추가 : 양식 '다중'..make

<input type="file" name="file-upload" /> 

..

@using (Html.BeginForm("Action", "Controller", null, FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
} 

가 ... 다음 컨트롤러에서 '파일을 통해 파일에 액세스를 요청 객체에 '모음 :

Request.Files["file-upload"]; 

당신이 아약스/JQuery와 함께 양식을 제출하고자하는 경우, 다음 파일을 직렬화 할 수있는 좀 더 많은 작업이 있습니다. 이 게시물은 다음과 관련하여 도움이됩니다. Sending multipart/formdata with jQuery.ajax

+0

고맙습니다. – Traffy

0
@model MVCDemo.Models.tbl_Images 
@{ 
    ViewBag.Title = "Create"; 
} 
<h2>Create</h2> 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 

    <fieldset> 
     <legend>ProductAllocationLog</legend> 
     <div class="editor-label"> 
      Date : 
     </div> 
     <div class="editor-field"> 
      @Html.TextBoxFor(model => model.Date, new { @class = "datepicker"}) 
      @Html.ValidationMessageFor(model => model.Date) 
     </div> 
     <div class="editor-label"> 
      Message : 
     </div> 
     <div class="editor-field"> 
      @Html.TextAreaFor(model => model.Message) 
      @Html.ValidationMessageFor(model => model.Message) 
     </div> 
     <div class="editor-label"> 
      Allocation : 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownList("Id_ProductAllocation", String.Empty) 
      @Html.ValidationMessageFor(model => model.Id_ProductAllocation) 
     </div> 
     <div class="demo" style="float:left; margin-top:5px;"> 

      <div id="aupload" style = "border:2px dashed #ddd; width:100px; height:100px; margin-right:10px; padding:10px; float:left;"></div> 
      <div id="uploaded" style = "border: 1px solid #ddd; width:550px; height:102px; padding:10px; float:left; overflow-y:auto;"></div> 

     </div> 
     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
} 
<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 
관련 문제