//public static System.Web.IHtmlString DtxCaptcha // (this System.Web.Mvc.HtmlHelper html, // int labelColumn = 3) //{ // string result = string.Empty; // if (Settings.Instance.DisplayCaptchaImage) // { // result += // "<div class=\"form-group\">"; // string caption = // Resources.DataDictionary.SecurityCode; // if ((labelColumn >= 1) && (labelColumn <= 12)) // { // result += // $"<label class=\"control-label col-sm-{ labelColumn }\">{ caption }</label>"; // } // else // { // result += // $"<label class=\"control-label\">{ caption }</label>"; // } // result += // $"<div class=\"col-sm-{ 12 - labelColumn }\">"; // result += // html.Captcha(6, MVC.Shared.Views.PartialViews._DisplayCaptchaImage) // .ToHtmlString(); // result += "</div>"; // result += "</div>"; // } // return html.Raw(result); //} public static System.Web.IHtmlString DtxDisplayNameAndValueFor <TModel, TValue> (this System.Web.Mvc.HtmlHelper <TModel> html, System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression, Enums.DisplayValueType displayValueType = Enums.DisplayValueType.Undefined, int labelColumn = 3, string caption = null //System.Web.Mvc.ActionResult actionResult = null ) { //System.Web.Mvc.IT4MVCActionResult oT4MVCActionResult = null; //if (actionResult != null) //{ // oT4MVCActionResult = // actionResult as System.Web.Mvc.IT4MVCActionResult; // if (oT4MVCActionResult == null) // { // return null; // } //} string result = "<div class='row'>"; System.Web.Mvc.ModelMetadata modelMetadata = System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData); // ************************************************** string labelStyle = "background-color: #f5f5f5; color: black; margin: 0px; padding: 4px; border: 1px solid darkgray"; string htmlFieldName = System.Web.Mvc.ExpressionHelper.GetExpressionText(expression); if (string.IsNullOrWhiteSpace(caption)) { caption = modelMetadata.DisplayName ?? modelMetadata.PropertyName ?? htmlFieldName.Split('.').Last(); } result += string.Format("<div class='col-sm-{0}' style='{1}'>", labelColumn, labelStyle); result += caption; result += "</div>"; // ************************************************** result += string.Format("<div class='col-sm-{0}'>", 12 - labelColumn); object valueObject = modelMetadata.Model; string valueString; if (valueObject == null) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; } else { switch (displayValueType) { case Enums.DisplayValueType.Number: { valueString = Convert.Number(valueObject); break; } case Enums.DisplayValueType.Percent: { valueString = Convert.Number(valueObject); valueString += " " + Resources.DataDictionary.Percent; break; } case Enums.DisplayValueType.Currency: { valueString = Convert.Number(valueObject); valueString += " " + Resources.DataDictionary.Currency; break; } case Enums.DisplayValueType.Date: { try { System.DateTime dateTime = System.Convert.ToDateTime(valueObject); valueString = Convert.DateTime(dateTime, displayTime: false); } catch (System.Exception ex) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; //Dtx.Logger.LogError // (type: typeof(CustomHtmlHelper), exception: ex); } break; } case Enums.DisplayValueType.DateTime: { try { System.DateTime dateTime = System.Convert.ToDateTime(valueObject); valueString = Convert.DateTime(dateTime, displayTime: true); } catch (System.Exception ex) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; //Dtx.Logger.LogError // (type: typeof(CustomHtmlHelper), exception: ex); } break; } case Enums.DisplayValueType.Raw: { valueString = html.Raw(valueObject).ToHtmlString(); break; } case Enums.DisplayValueType.Url: { valueString = string.Format("<a href='{0}'>{0}</a>", valueObject); break; } case Enums.DisplayValueType.EmailAddress: { valueString = string.Format("<a href='mailto:{0}'>{0}</a>", valueObject); break; } default: { valueString = html.DisplayFor(expression).ToHtmlString(); break; } } } result += valueString; //if (actionResult == null) //{ // result += valueString; //} //else //{ // System.Web.Mvc.UrlHelper oUrlHelper = // new System.Web.Mvc.UrlHelper(html.ViewContext.RequestContext); // //strResult += oUrlHelper.Action // // (oT4MVCActionResult.Action, // // oT4MVCActionResult.Controller, // // oT4MVCActionResult.RouteValueDictionary); // result += // html.ActionLink(linkText: valueString, // actionName: oT4MVCActionResult.Action, // controllerName: oT4MVCActionResult.Controller, // routeValues: oT4MVCActionResult.RouteValueDictionary, // htmlAttributes: null); //} result += " </div>"; result += "</div>"; return(html.Raw(result)); }