本文整理汇总了C#中System.Web.Mvc.HtmlHelper.HiddenFor方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.HiddenFor方法的具体用法?C# HtmlHelper.HiddenFor怎么用?C# HtmlHelper.HiddenFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.HiddenFor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HiddenForWithBinaryArrayValueRendersBase64EncodedValue
public void HiddenForWithBinaryArrayValueRendersBase64EncodedValue() {
// Arrange
Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
Mock<IViewDataContainer> mockIViewDataContainer = new Mock<IViewDataContainer>();
ViewDataDictionary viewData = new ViewDataDictionary(new Gallery { TimeStamp = new Binary(ByteArrayModelBinderTest.Base64TestBytes) });
mockIViewDataContainer.Expect(c => c.ViewData).Returns(viewData);
HtmlHelper<Gallery> htmlHelper = new HtmlHelper<Gallery>(mockViewContext.Object, mockIViewDataContainer.Object);
// Act
string result = htmlHelper.HiddenFor(g => g.TimeStamp);
// Assert
Assert.AreEqual("<input id=\"TimeStamp\" name=\"TimeStamp\" type=\"hidden\" value=\"Fys1\" />", result);
}
示例2: HiddenForWithByteArrayValueRendersBase64EncodedValue
public void HiddenForWithByteArrayValueRendersBase64EncodedValue() {
// Arrange
Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
Mock<IViewDataContainer> mockIViewDataContainer = new Mock<IViewDataContainer>();
ViewDataDictionary viewData = new ViewDataDictionary(new Gallery { Image = Base64TestBytes });
mockIViewDataContainer.Expect(c => c.ViewData).Returns(viewData);
mockViewContext.Expect(c => c.ViewData).Returns(viewData);
HtmlHelper<Gallery> htmlHelper = new HtmlHelper<Gallery>(mockViewContext.Object, mockIViewDataContainer.Object);
// Act
MvcHtmlString result = htmlHelper.HiddenFor(g => g.Image);
// Assert
Assert.AreEqual("<input id=\"Image\" name=\"Image\" type=\"hidden\" value=\"Fys1\" />", result.ToHtmlString());
}
示例3: HiddenForWithAttributesAndExpressionRendersAttributes
public void HiddenForWithAttributesAndExpressionRendersAttributes() {
// Arrange
Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
ViewDataDictionary viewData = new ViewDataDictionary(new Product { ProductName = "ASP.NET MVC" });
Mock<IViewDataContainer> mockIViewDataContainer = new Mock<IViewDataContainer>();
mockIViewDataContainer.Expect(c => c.ViewData).Returns(viewData);
mockViewContext.Expect(c => c.ViewData).Returns(viewData);
HtmlHelper<Product> htmlHelper = new HtmlHelper<Product>(mockViewContext.Object, mockIViewDataContainer.Object);
// Act
MvcHtmlString result = htmlHelper.HiddenFor(p => p.ProductName, new { @class = "test-css-class" });
// Assert
Assert.AreEqual("<input class=\"test-css-class\" id=\"ProductName\" name=\"ProductName\" type=\"hidden\" value=\"ASP.NET MVC\" />", result.ToHtmlString());
}
示例4: HiddenForWithExpressionRendersInputTagUsingExpressionUsingValueFromModelState
public void HiddenForWithExpressionRendersInputTagUsingExpressionUsingValueFromModelState() {
// Arrange
Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
ViewDataDictionary viewData = new ViewDataDictionary(new Product { ProductName = "ASP.NET MVC" });
viewData.ModelState.SetModelValue("ProductName", new ValueProviderResult("Something Else", "Something Else", CultureInfo.InvariantCulture));
Mock<IViewDataContainer> mockIViewDataContainer = new Mock<IViewDataContainer>();
mockIViewDataContainer.Expect(c => c.ViewData).Returns(viewData);
mockViewContext.Expect(c => c.ViewData).Returns(viewData);
HtmlHelper<Product> htmlHelper = new HtmlHelper<Product>(mockViewContext.Object, mockIViewDataContainer.Object);
// Act
MvcHtmlString result = htmlHelper.HiddenFor(p => p.ProductName);
// Assert
Assert.AreEqual("<input id=\"ProductName\" name=\"ProductName\" type=\"hidden\" value=\"Something Else\" />", result.ToHtmlString());
}
示例5: HiddenForWithExpressionRendersInputTagUsingExpression
public void HiddenForWithExpressionRendersInputTagUsingExpression() {
// Arrange
Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
ViewDataDictionary viewData = new ViewDataDictionary(new Product { ProductName = "ASP.NET MVC" });
Mock<IViewDataContainer> mockIViewDataContainer = new Mock<IViewDataContainer>();
mockIViewDataContainer.Expect(c => c.ViewData).Returns(viewData);
HtmlHelper<Product> htmlHelper = new HtmlHelper<Product>(mockViewContext.Object, mockIViewDataContainer.Object);
// Act
string result = htmlHelper.HiddenFor(p => p.ProductName);
// Assert
Assert.AreEqual("<input id=\"ProductName\" name=\"ProductName\" type=\"hidden\" value=\"ASP.NET MVC\" />", result);
}