经过多年与WebForms的合作,我最近开始向MVC过渡.我正在尝试创建一个可插入的轻量级内容编辑模块,但我遇到了一些问题.
这个想法很简单:创建一个名为EditableSimpleHtml的HtmlHelper,可以在@using ... {}语法中使用,以便在剃刀视图中实现以下功能:
@using (Html.EditableSimpleHtml("MyKey"))
{
<h3>Test</h3>
<p>
1<br />
</p>
}
Run Code Online (Sandbox Code Playgroud)
{...}之间的值是在数据存储中找不到内容时的默认值.
我创建了一个HtmlHelper.以下是简化版本:
public static IDisposable EditableSimpleHtml(this HtmlHelper helper, string key)
{
// Get the content from the data storage using the key (I will not show the provider itself, its just a provider that will access a db)
var provider = ContentEditing.Provider;
string value = provider.GetValue(key);
if (value == null)
{
// No value found in the data storage for the supplied key, we have to use …Run Code Online (Sandbox Code Playgroud)