/// <summary> /// Editable label with daterange label. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <param name="htmlHelper">The html helper</param> /// <param name="expressionStart">The expression of the start date</param> /// <param name="expressionEnd">The expression of the end date</param> /// <param name="htmlAttributes">The html attributes</param> /// <returns></returns> public static MvcHtmlString EditableDateRangeLabelFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expressionStart, Expression <Func <T, U> > expressionEnd, object htmlAttributes = null) { ModelMetadata modelMetadataStart = ModelMetadata.FromLambdaExpression(expressionStart, htmlHelper.ViewData); ModelMetadata modelMetadataEnd = ModelMetadata.FromLambdaExpression(expressionEnd, htmlHelper.ViewData); string textToDisplay = string.Empty; if (modelMetadataStart.Model != null && modelMetadataEnd.Model != null) { textToDisplay = ((DateTime)modelMetadataStart.Model).ToShortDateString() + " - " + ((DateTime)modelMetadataEnd.Model).ToShortDateString(); } return(DivExtensions.CreateSpan(htmlHelper, textToDisplay, htmlAttributes)); //return ExtensionsUtil.CreateLabel(modelMetadataStart.PropertyName, textToDisplay, htmlAttributes); }
/// <summary> /// The label for the referenced object. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <param name="htmlHelper">The html helper</param> /// <param name="expression">The expression</param> /// <param name="action">The name of the action to run after the click</param> /// <param name="controller">The name of the controller to run after the click</param> /// <param name="htmlAttributes">The html attributes</param> /// <returns>The label for the referenced object</returns> public static MvcHtmlString ReferenceLabelFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expression, string action = null, string controller = null, object htmlAttributes = null) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); if (metadata.Model == null || !(metadata.Model is ReferenceString)) { return(DivExtensions.CreateSpan <T>(htmlHelper, SharedConstants.EMPTY_STRING, htmlAttributes)); // return ExtensionsUtil.CreateLabel(metadata.PropertyName, SharedConstants.EMPTY_STRING, htmlAttributes); } //Dictionary<Guid, string> referencies = (metadata.Model as ReferenceString).GetReferencies(); if (action == null && controller == null) { return(DivExtensions.CreateSpan <T>(htmlHelper, (metadata.Model as ReferenceString).GetValues(), htmlAttributes)); } return(MvcHtmlString.Create(CreateLinks <T>(htmlHelper, metadata.Model as ReferenceString, action, controller, htmlAttributes))); }
/// <summary> /// Display the localized raw text of the enum value. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <param name="htmlHelper">The html helper</param> /// <param name="expression">The expression for the property</param> /// <param name="htmlAttributes">The html attributes</param> /// <returns>Returns the localized raw text of the selected value</returns> public static MvcHtmlString LocalizedDropDownDisplayFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expression, object htmlAttributes = null) { ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); if (modelMetadata == null || modelMetadata.Model == null) { return(MvcHtmlString.Create(string.Empty)); } List <SelectListItem> selectListItem = CreateListItems <U>(modelMetadata.ContainerType, Enum.GetValues(typeof(U)).Cast <U>(), modelMetadata); SelectListItem selectedValue = selectListItem.Where(f => f.Value.Equals(modelMetadata.Model.ToString())).FirstOrDefault(); if (selectedValue == null) { //return EditableControlExtensions.CreateLabel(htmlHelper, modelMetadata.PropertyName, selectListItem.First().Text, htmlAttributes); return(DivExtensions.CreateSpan <T>(htmlHelper, selectListItem.First().Text, htmlAttributes)); } //return EditableControlExtensions.CreateLabel(htmlHelper, modelMetadata.PropertyName, selectedValue.Text, htmlAttributes); return(DivExtensions.CreateSpan <T>(htmlHelper, selectedValue.Text, htmlAttributes)); }