好的,这是我的情况,已经到了这个……戏剧性的停顿……
我的 MVC 视图中有以下 TextAreaFor<> 框:
<div class="editor-label">
<%: Html.LabelFor(model => model.Monday) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(model => model.Wednesday, 6, 40, new { })%>
<%: Html.ValidationMessageFor(model => model.Monday) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Wednesday) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(model => model.Wednesday, 6, 40, new {})%>
<%: Html.ValidationMessageFor(model => model.Wednesday) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Friday) %>
</div>
<div class="editor-field">
<%: Html.TextAreaFor(model => model.Friday, 6, 40, new {}) %>
<%: Html.ValidationMessageFor(model => model.Friday) %>
</div>
对于那些有很多经验的人,你可能已经注意到我使用强类型视图来减少开发时间,所以这里有很多默认项。
我需要知道,如何设置 TextAreaFor<> 框的默认值?IE,我可能想要其中的文本作为模板。用户添加到这些 textAreas 的任何内容都将存储在数据库中(后端已经完成且功能齐全)。正如文章ASP.NET MVC - How can I set the Default Value in a Strongly Typed TextArea? ,我不确定我是否可以使用这种方法,因为我不确定模型变量是否会被发送回我的控制器。
另一个快速问题(QuestionCeption)如果我将这些 textAreas 中的数据保存到数据库中(使用 SQL Server Express 2008),它会保留换行符吗?
这是我需要的默认值示例。
Traditional:
Healthy Lifestyle:
Chill out:
Vegetarian:
Soup:
Sandwich:
No thanks.