我通过以下代码绑定了mvc中的DATA:
@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
中没有看到的值。
下面是我的控制器代码,通过它我将数据发布到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 :(得分:0)
据我所知,你不能用textarea这样做,因为它与Model.Data
的值绑定。
在使用textareafor之前,你能否宣布你的Model.Data
= ViewBag.DocumentData
?
编辑:例如:
@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)
}