本文整理汇总了C#中System.Web.Mvc.HtmlHelper.SerializedHidden方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.SerializedHidden方法的具体用法?C# HtmlHelper.SerializedHidden怎么用?C# HtmlHelper.SerializedHidden使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.SerializedHidden方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialized_Hidden_Returns_A_Hidden_Field_With_The_Entity_Serialized
public void Serialized_Hidden_Returns_A_Hidden_Field_With_The_Entity_Serialized()
{
//Arrang
Customer customer = new Customer();
string serializedCustomer = new SelfTrackingEntityBase64Converter<Customer>().ToBase64(customer);
ViewDataDictionary viewData = new ViewDataDictionary();
SViewContext viewContext = new SViewContext();
viewContext.ViewData = viewData;
SIViewDataContainer viewDataContainer = new SIViewDataContainer();
viewDataContainer.ViewDataGet = () => viewData;
HtmlHelper<Customer> helper = new HtmlHelper<Customer>(viewContext, viewDataContainer);
//Act
MvcHtmlString result = helper.SerializedHidden(customer);
//Assert
//Parse the result (it creates XML-Compliant HTML)
XElement element = XElement.Parse(result.ToHtmlString());
//Ensure it's an input tag.
Assert.AreEqual("input", element.Name.LocalName);
//Ensure it's a hidden field.
Assert.AreEqual("hidden",element.Attribute("type").Value);
//Ensure it has the correct name
Assert.AreEqual("CustomerSTE",element.Attribute("name").Value);
//Ensure it has the correct id
Assert.AreEqual("CustomerSTE",element.Attribute("id").Value);
//Ensure the serialized customer is serialized correctly.
Assert.AreEqual(serializedCustomer, element.Attribute("value").Value);
}
示例2: Serialized_Hidden_Returns_An_Empty_String_When_Entity_Is_Null
public void Serialized_Hidden_Returns_An_Empty_String_When_Entity_Is_Null()
{
//Arrange
ViewDataDictionary viewData = new ViewDataDictionary();
SViewContext viewContext = new SViewContext();
viewContext.ViewData = viewData;
SIViewDataContainer viewDataContainer = new SIViewDataContainer();
viewDataContainer.ViewDataGet = () => viewData;
HtmlHelper<Customer> helper = new HtmlHelper<Customer>(viewContext, viewDataContainer);
//Act
MvcHtmlString result = helper.SerializedHidden(null);
//Assert
Assert.AreEqual(MvcHtmlString.Empty.ToHtmlString(), result.ToHtmlString());
}