public static MvcHtmlString UnitHtml(this HtmlHelper htmlhelper, UnitProject up)
{
StringBuilder sb = new StringBuilder();
htmlhelper.HiddenFor()
}
我想调用
HiddenFor()方法改如何做
在里面写lambda表达式。
/// <summary>
/// 通过lambda表达式生成控件
/// </summary>
/// <param name="helper">HtmlHelper对象</param>
/// <param name="expression">lambda表达式,指定要显示的属性及其所属对象</param>
/// <param name="format">显示格式</param>
/// <returns>Html文本</returns>
public static string CalendarFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, string format)
{
string name = ExpressionHelper.GetExpressionText(expression);
DateTime value;
object data = ModelMetadata.FromLambdaExpression<TModel, TProperty>(expression, helper.ViewData).Model;
if (data != null && DateTime.TryParse(data.ToString(), out value))
{
return GenerateHtml(name, value, format);
}
else
{
return GenerateHtml(name, null, format);
}
}
/// <summary>
/// 生成输入框的Html
/// </summary>
/// <param name="name">calendar的名称</param>
/// <param name="date">calendar的值</param>
/// <returns>html文本</returns>
private static string GenerateHtml(string name, DateTime? date, string format)
{
if (date != null)
{
return "<input type=\"text\" id=\"" + name + "\" name=\"" + name + "\" onfocus=\"WdatePicker({dateFmt:'" + format + "'})\" class=\"Wdate\" value=\"" + date.Value.ToString(format) + "\" />";
}
else
{
return "<input type=\"text\" id=\"" + name + "\" name=\"" + name + "\" onfocus=\"WdatePicker({dateFmt:'" + format + "'})\" class=\"Wdate\" value=\"\" />";
}
}
这是 我写的一个日期的 你看看那就知道了