【发布时间】:2018-09-07 18:04:58
【问题描述】:
不确定是否可以在此处发布,但我有一个文本区域,允许用户在其中添加长描述,但我不知道如何将其保存为 HTML 格式,以便以相同的方式显示。
我在我的文本区域中输入如下,但它保存在“一行”中并以这种方式显示,没有发现有“段落(即按两次输入)”
PS:我将它保存在我的数据库中,所以并不是我不知道如何保存数据,它只是以一种在提取数据时显示的方式保存它,它会显示它的方式我输入的不是一行。
例子:
Hi there
This is a description including "enter" character, or even bullets
• Slow turnaround times
• Branches unable to assist with certain queries
• Letters/emails are too complicated to understand
我读到有人说你必须使用 CKEditor,但这真的有必要吗?它会以相同格式显示的方式保存数据吗?这不能用普通的文本区域来完成吗?我试图让它尽可能简单。
这是我目前使用的:
<textarea class="form-control input-sm" rows="5" cols="3" placeholder="Challenge Description" type="text" name="challengedescription" id="challengedescription" value="@Model.ChallengeDescription" rel="popover-hover" data-placement="top" data-original-title="Challenge Description" data-content="Provide context to the business problem or opportunity that you have identified for innovation. Including statistics and facts are great to contextualise your innovation opportunity! Define the problem statement which speaks to the root of the problem or opportunity. Ensure that there is a clear call to action. E.g. what, by when and the desired outcome."></textarea>
我正在尝试这样显示:
<p>
@Html.Raw(Model.ChallengeDescription)
</p>
提前致谢。
【问题讨论】:
-
为什么不使用C#并将其保存在后端某处,并在加载页面时通过
ViewBag传递? -
我将它保存在 SQL DB 中,但是当我提取数据时,它会在一行中显示所有内容,而不是输入和保存的方式。这就是问题所在。
-
<p stype="white-space: pre-line">元素中的内容(浏览器默认折叠空白,除非您设置样式) -
谢谢斯蒂芬,但问题实际上不在于它是如何保存在数据库中的吗?我尝试在我的
标记中进行上述更改,但没有任何改变。
标签: c# html asp.net-mvc razor