2016-07-06 2 views
1

내가 MVC의 데이터를 결합하고에 표시되지 :데이터 코드 아래를 통해 텍스트 영역

@model DocumentManagementSystem.Models.DocumentFileName 
@{ 
    ViewBag.Title = "Index"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    <table style="margin-top:50px;"> 
     <tr> 
      <td> 
       <input type="file" name="file" /> 
      </td> 
      <td> 
       <input type="submit" name="Submit" id="Submit" value="Upload" /> 
      </td> 
     </tr> 
    </table> 
    @Html.TextAreaFor(f => f.Data, new { ViewBag.DocumentData }) 
} 

DATA (데이터) 바인드 Viewbag에서입니다. 이 값은 textarea으로 지정합니다. 소스에서 F12 사용을 보여 주지만 UI 부분에는 표시되지 않습니다. 나는 그것을 위해 스크린 샷을 첨부했습니다 : 나는 같은 textarea에서 볼되지 않은 값을 강조했습니다

shows in code but not in ui

. 다음은

내가 Viewbag에 데이터를 게시 통해 내 컨트롤러 코드 :

 [HttpPost] 
     public ActionResult Upload() 
     { 
      if (Request.Files.Count > 0) 
      { 
       var file = Request.Files[0]; 
       object filename = Path.Combine(Server.MapPath("~/Document/"), file.FileName); 
       Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass(); 
       Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document(); 
       object readOnly = false; 
       object isVisible = true; 
       object missing = System.Reflection.Missing.Value; 
       var retString = ""; 
       try 
       { 
        doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible); 
        retString = doc.Content.Text; 
       } 
       catch (Exception ex) 
       { 
        retString = ex.ToString(); 
       } 
       ViewBag.DocumentData = new MvcHtmlString(System.Web.HttpUtility.HtmlDecode(retString.ToString())); 
      } 
      else 
      { 
       ViewBag.result = "Document Not Support"; 
      } 
      return View("Index"); 

     } 

답변

0

당신은 정말 할 수없는 textareafor와 지금까지이 값에 바인딩되어 있기 때문에 내가 알고 있어요로 Model.Data.

textareafor를 사용하기 바로 전에 Model.Data을 (를)(으)로 신고 할 수 없습니까?

편집 : 예 : : 당신을 받고 있지 않다

@model DocumentManagementSystem.Models.DocumentFileName 
@{ 
    ViewBag.Title = "Index"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
    Model.Data = ViewBag.DocumentData; 
} 

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

    @Html.TextAreaFor(f => f.Data) 
} 
+0

, 그것을 설명하십시오. – Bhupendra

+0

면도기 파일 상단에 모델을 정의했습니다. 'DocumentManagementSystem.Models.DocumentFileName'. TextAreaFor는 해당 모델의 "데이터"속성에 바인딩됩니다. TextAreaFor를 사용하기 전에'Model.Data = ViewBag.DocumentData'를 설정하면 생성 된 텍스트 영역은'ViewBag.DocumentData'를 설정 한 값을 갖게됩니다. –

+0

여기서 'Model.Data = ViewBag.DocumentData'를 설정합니까 – Bhupendra