I'm trying to generate a TextArea box with default value supplied by the controller. Given this markup which calls a partial view:
@{
Html.RenderAction(
"ContentBlock", "ContentBlock",
new TestSiteMvc.Models.ContentModel() { ContentID = 3 }
);
}
Partial View:
@Html.TextBoxFor(m=>m.Title)
@Model.ContentHtml<br />
@Html.TextAreaFor(m => m.ContentHtml)
@Html.TextBoxFor(m => m.ContentHtml)
@Html.TextArea("ContentHtml2", Model.ContentHtml)
@Model.ContentHtml<br />
The resulting HTML rendered is:
<input id="Title" name="Title" type="text" value="Home Title" />
Home Page Content<br />
<textarea cols="20" id="ContentHtml" name="ContentHtml" rows="2"></textarea>
<input id="ContentHtml" name="ContentHtml" type="text" value="Home Page Content" />
<textarea cols="20" id="ContentHtml2" name="ContentHtml2" rows="2">Home Page Content</textarea>
Home Page Content<br />
So, it's clear the ContentHtml property is getting populated. What I don't understand is why TextAreaFor is getting rendered with an empty value. And to be clear, when I remove the line @Html.TextBoxFor(m => m.ContentHtml) as to not incur tags with the same id, the issue does not go away.
Controller:
[HttpGet]
public ActionResult ContentBlock(Models.ContentModel mcontent) {
mcontent = new Models.ContentModel() {
ContentID = 3,
ContentHtml = "Home Page Content",
Title = "Home Title" };
return PartialView(mcontent);
}
Model:
public class ContentModel {
public int ContentID { get; set; }
public string Link { get; set; }
public string Title { get; set; }
public string ContentHtml { get; set; }
public DateTime LastModifiedDate { get; set; }
}