I'm working with an MVC view that displays some text with HTML markup. I have the field defined in my view model like this:
public class RequestReviewViewModel
{
[Display(Name = "Email Body")]
[AllowHtml]
[DataType(DataType.MultilineText)]
public string LetterTemplateBody { get; set; }
}
When the user selects a new option in a dropdown list I am catching the postback and updating the field with new data to display in a TextArea. However the TextArea doesn't change.
I have this code in my controller:
var letterTemplList =
db.EmailBodyTemplate.Where(x => x.EmailTemplateTypeId == (int)EmailTemplateTypes.requestreview).ToList();
ViewBag.LetterTemplates =
new SelectList(letterTemplList, "EmailTemplateId", "EmailTemplateName");
var letterTemplate =
letterTemplList.Find(x => x.EmailTemplateId == thisModel.LetterTemplateId);
thisModel.LetterTemplateBody =
letterTemplate == null ? letterTemplList.First().Body : letterTemplate.Body;
// in this case, mode == "letterTemplate"
if (mode == "reviewRole" || mode == "letterTemplate" || !ModelState.IsValid)
{
if (model.InitialRoleId != model.SelectedRoleId)
model.SelectedProjectReviewers = GetReviewerProfiles(model.ProjectId, model.SelectedRoleId);
return View(model);
}
This is where the field is displayed:
<div class="row">
@Html.LabelFor(model => model.LetterTemplateBody, new { @class = "control-label" })
@Html.TextAreaFor(model => model.LetterTemplateBody,
new { @class = "form-control", @style = "max-width:100%;height:400px;font-size:11px;" })
</div>
<p>@Model.LetterTemplateBody</p>
With the debugger, I can see the model.LetterTemplateBody
has the new results. However, when I look at the page (in chrome) the value/data hasn't changed in the TextArea, but the <p>
has.
What could be causing what the textarea to not get updated? Other callbacks update the page with the same controller actions.
Here is how it's rendered in the browser:
<textarea
class="form-control"
cols="20"
id="LetterTemplateBody"
name="LetterTemplateBody"
rows="2"
style="max-width:100%;height:400px;font-size:11px;">
Text from initial load
</textarea>
@Model.LetterTemplateBody
in the cshtml? – Danny Nov 12 '15 at 16:41