Reputation: 13
I am using asp.net mvc to do model binding. When I pass a model to a view I am able to see the model data displayed in the form inside a label
<%= Html.Label(Model.title) %>
<%= Html.Label(Model.description) %>
However I am not able to do the same using
<%= Html.TextArea(Model.description)%>
Is there a syntax difference between displaying in a label as oppsed to a textbox?
Here is my view
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EditDocumentViewData>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Update
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
<h2>Update</h2>
<form id="myForm" action="<%=Url.Action("Update") %>" method="post" >
<% Html.EnableClientValidation(); %>
<div id="validationSummary"><%= Html.ValidationSummary() %> </div>
<%= Html.ClientSideValidation(typeof(Document))
.UseValidationSummary("validationSummary") %>
<div style="float:left">
<input type="button" class="btnpost" id="btnMain" value="Main Thumb"/>
<input id="btnDelete" class="btnpost" type="button" value="Delete"/>
<br /> <br /> <br />
<br /> <br /> <br /> <br />
<table>
<%= Html.HiddenFor(m => m.id)%>
<tr> <td> <%=Html.Label("Title")%></td><td>
<%=Html.TextBox("title", Model.title)%>
</td> </tr>
<tr> <td> <%=Html.Label("Description")%></td><td>
<%= Html.TextArea("description", Model.description)%>
</td>
<td>
<%= Html.ValidationMessage("description")%>
</td>
</tr><tr><td> <%=Html.Label("Summary")%></td><td>
<%= Html.TextAreaFor(m=>m.summary)%>
</td> <td>
<%= Html.ValidationMessage("summary")%>
</td></tr>
</form>
</asp:Content>
my contollers actions are
[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Update(int Id)
{
Document doc= _documentRepository.GetById(Id);
EditDocumentViewData documentViewData=new EditDocumentViewData();
documentViewData.id = doc.document_id;
documentViewData.category = doc.Category1.name;
documentViewData.title = doc.title;
documentViewData.Thumbs = doc.Thumbs.ToList();
documentViewData.description = doc.description;
documentViewData.summary = doc.summary;
return View(documentViewData);
// TempData["docid"] = doc.document_id;
//if (doc != null)
// return View(doc);
//else
// return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(EditDocumentViewData editDoc)
{
Document doc= _documentRepository.GetById(editDoc.id);
doc.title = editDoc.title;
doc.description = editDoc.description;
doc.summary = editDoc.summary;
_unitOfWorkManager.Commit();
return RedirectToAction("Index");
}
Upvotes: 1
Views: 3724
Reputation: 532455
In your usage, the first two create label
elements and use the argument for the both the text of the label
and the label's for
property. The third will create a textarea
, but it uses the argument as the name for the area. If you want the textarea
to contain the contents of the description, you need to use a different signature.
<%= Html.TextArea( "Description", Model.Description ) %>
or use the strongly-typed helper
<%= Html.TextAreaFor( m => m.Description ) %>
On another node, if you simply want to display the contents of the model property, you should be using Encode
or the newer <%: %>
syntax (in ASP.NET 4).
<span class="description">
<%= Html.Encode( Model.Description ) %>
</span>
Upvotes: 3
Reputation: 13083
<%= Html.TextAreaFor(model => model.Description, 4, 10, new { style = "width: 100%", @class = "textarea" })%>
Upvotes: 2