本文整理汇总了C#中FormContext.RenderedField方法的典型用法代码示例。如果您正苦于以下问题:C# FormContext.RenderedField方法的具体用法?C# FormContext.RenderedField怎么用?C# FormContext.RenderedField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormContext
的用法示例。
在下文中一共展示了FormContext.RenderedField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUnobtrusiveValidationAttributesMarksRenderedFieldsWithFullName
public void GetUnobtrusiveValidationAttributesMarksRenderedFieldsWithFullName()
{
// Arrange
var formContext = new FormContext();
var viewContext = new Mock<ViewContext>();
var viewData = new ViewDataDictionary();
viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
viewData.TemplateInfo.HtmlFieldPrefix = "Prefix";
var viewDataContainer = MvcHelper.GetViewDataContainer(viewData);
var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
// Act
htmlHelper.GetUnobtrusiveValidationAttributes("foobar");
// Assert
Assert.False(formContext.RenderedField("foobar"));
Assert.True(formContext.RenderedField("Prefix.foobar"));
}
示例2: GetUnobtrusiveValidationAttributesReturnsEmptySetAndSetsFieldAsRenderedForFieldWithNoClientRules
public void GetUnobtrusiveValidationAttributesReturnsEmptySetAndSetsFieldAsRenderedForFieldWithNoClientRules()
{
// Arrange
var formContext = new FormContext();
var viewContext = new Mock<ViewContext>();
viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
htmlHelper.ClientValidationRuleFactory = delegate { return Enumerable.Empty<ModelClientValidationRule>(); };
// Act
IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");
// Assert
Assert.Empty(result);
Assert.True(formContext.RenderedField("foobar"));
}
示例3: GetUnobtrusiveValidationAttributesReturnsEmptySetWhenFieldHasAlreadyBeenRendered
public void GetUnobtrusiveValidationAttributesReturnsEmptySetWhenFieldHasAlreadyBeenRendered()
{
// Arrange
var formContext = new FormContext();
formContext.RenderedField("foobar", true);
var viewContext = new Mock<ViewContext>();
viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
// Act
IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");
// Assert
Assert.Empty(result);
}
示例4: CanSetRenderedFieldToBeTrue
public void CanSetRenderedFieldToBeTrue()
{
// Arrange
var context = new FormContext();
var name = Guid.NewGuid().ToString();
context.RenderedField(name, true);
// Act
bool result = context.RenderedField(name);
// Assert
Assert.True(result);
}
示例5: RenderedFieldIsFalseByDefault
public void RenderedFieldIsFalseByDefault()
{
// Arrange
var context = new FormContext();
// Act
bool result = context.RenderedField(Guid.NewGuid().ToString());
// Assert
Assert.False(result);
}
示例6: GetUnobtrusiveValidationAttributesReturnsEmptySetWhenClientValidationIsNotEnabled
public void GetUnobtrusiveValidationAttributesReturnsEmptySetWhenClientValidationIsNotEnabled() {
// Arrange
var formContext = new FormContext();
formContext.RenderedField("foobar", true);
var viewContext = new Mock<ViewContext>();
viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
// Act
IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");
// Assert
Assert.AreEqual(0, result.Count);
}