1
我想要有一個自定義視圖模式,以顯示在線用戶文本,而不是在線用戶一些其他文本。防止發生使用陳述
但我想在使用聲明中這樣做,如Html.BeginForm()
。
我已經做了一個女巫可以在使用和文本開始時寫文本,但我不能讓它停止發生{}中的文本。
@using (AuthorizedContent(Html, "Adminstrator"))
{
<text>Only the administrator should see this</text>
}
與
public static Test AuthorizedContent(this HtmlHelper helper, String roleName)
{
return null;
var test = new Test(helper);
return test;
}
public class Test : IDisposable
{
private HtmlHelper _helper;
public Test(HtmlHelper helper) {
_helper = helper;
this.StartTag();
}
public void StartTag()
{
var writer = _helper.ViewContext.Writer;
writer.Write("Hello");
}
public void EndTag()
{
var writer = _helper.ViewContext.Writer;
writer.Write("Hello");
}
void IDisposable.Dispose()
{
this.EndTag();
}
}
我不明白它 - 只需刪除四行,它們不會發生。什麼是真正的目標? – sehe
爲什麼要防止渲染使用語句的正文?有什麼意義? –
@KirkWoll:我猜想,當用戶不是管理員時,OP想要阻止使用語句的主體進行呈現。 – dtb