Exemple #1
0
        private IEnumerable <SelectListItem> GetSelectData(string name)
        {
            object o = null;

            if (ViewData != null)
            {
                o = ViewData.Eval(name);
            }
            if (o == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              MvcResources.HtmlHelper_MissingSelectData,
                              name,
                              "IEnumerable<SelectListItem>"
                              )
                          );
            }
            IEnumerable <SelectListItem> selectList = o as IEnumerable <SelectListItem>;

            if (selectList == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              MvcResources.HtmlHelper_WrongSelectDataType,
                              name,
                              o.GetType().FullName,
                              "IEnumerable<SelectListItem>"
                              )
                          );
            }
            return(selectList);
        }
Exemple #2
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (!DesignMode && String.IsNullOrEmpty(Name))
            {
                throw new InvalidOperationException(MvcResources.CommonControls_NameRequired);
            }

            string stringValue = String.Empty;

            if (ViewData != null)
            {
                object rawValue = ViewData.Eval(Name);

                if (String.IsNullOrEmpty(Format))
                {
                    stringValue = Convert.ToString(rawValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    stringValue = String.Format(CultureInfo.CurrentCulture, Format, rawValue);
                }
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Name, Name);
            if (!String.IsNullOrEmpty(ID))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, ID);
            }

            bool wasTruncated = false;

            if ((TruncateLength >= 0) && (stringValue.Length > TruncateLength))
            {
                stringValue  = stringValue.Substring(0, TruncateLength);
                wasTruncated = true;
            }

            switch (EncodeType)
            {
            case EncodeType.Html:
                writer.Write(HttpUtility.HtmlEncode(stringValue));
                break;

            case EncodeType.HtmlAttribute:
                writer.Write(HttpUtility.HtmlAttributeEncode(stringValue));
                break;

            case EncodeType.None:
                writer.Write(stringValue);
                break;
            }

            if (wasTruncated)
            {
                writer.Write(TruncateText);
            }
        }
Exemple #3
0
        private IEnumerable GetValue()
        {
            ModelState state;

            if (ViewData.ModelState.TryGetValue(Name, out state) && (state.Value != null))
            {
                //if (ViewData.ModelState.IsValidField(Name)) TODO: Do I need this ?
                return(state.Value.ConvertTo(typeof(string[]), null) as IEnumerable);
            }
            else if (Value == null)
            {
                return(ViewData.Eval(Name) as IEnumerable);
            }

            return(Value);
        }
Exemple #4
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Dummy control to which we parent all the data item controls
            Control containerControl = new Control();

            IEnumerable dataItems = ViewData.Eval(Name) as IEnumerable;
            bool        hasData   = false;

            if (dataItems != null)
            {
                int index = 0;
                foreach (object dataItem in dataItems)
                {
                    hasData = true;
                    RepeaterItem repeaterItem = new RepeaterItem(index, dataItem)
                    {
                        ViewData = new ViewDataDictionary(dataItem),
                    };
                    ItemTemplate.InstantiateIn(repeaterItem);
                    containerControl.Controls.Add(repeaterItem);

                    index++;
                }
            }

            if (!hasData)
            {
                // If there was no data, instantiate the EmptyDataTemplate
                Control emptyDataContainer = new Control();
                EmptyDataTemplate.InstantiateIn(emptyDataContainer);
                containerControl.Controls.Add(emptyDataContainer);
            }

            Controls.Add(containerControl);

            containerControl.DataBind();
        }
Exemple #5
0
        #pragma warning disable 1998
        public async override global::System.Threading.Tasks.Task ExecuteAsync()
        {
#line 1 "E:\Team Xente\Applications\AspNetCore\Azure Applications\ProductManagement\Views\Shared\Error.cshtml"

            var message = ViewData.Eval("Message") as string;

#line default
#line hidden
            BeginContext(63, 160, true);
            WriteLiteral("\r\n\r\n<h3>\r\n    An error occured while processing your request. \r\n    The support team is notified and we are working on the fix\r\n</h3>\r\n\r\n<small>Error Message = ");
            EndContext();
            BeginContext(224, 7, false);
#line 11 "E:\Team Xente\Applications\AspNetCore\Azure Applications\ProductManagement\Views\Shared\Error.cshtml"
            Write(message);

#line default
#line hidden
            EndContext();
            BeginContext(231, 76, true);
            WriteLiteral("</small>\r\n<h5>\r\n    Please contact us on [email protected]\r\n</h5>\r\n\r\n");
            EndContext();
        }
Exemple #6
0
 public string Eval(string expression, string format)
 {
     return(ViewData.Eval(expression, format));
 }
Exemple #7
0
 public object Eval(string expression)
 {
     return(ViewData.Eval(expression));
 }
Exemple #8
0
 internal bool EvalBoolean(string key)
 {
     return(Convert.ToBoolean(ViewData.Eval(key), CultureInfo.InvariantCulture));
 }
Exemple #9
0
 internal string EvalString(string key, string format)
 {
     return(Convert.ToString(ViewData.Eval(key, format), CultureInfo.CurrentCulture));
 }
        protected override void Render(HtmlTextWriter writer)
        {
            if (!DesignMode && String.IsNullOrEmpty(Name))
            {
                throw new InvalidOperationException(MvcResources.CommonControls_NameRequired);
            }

            SortedDictionary <string, string> attrs = new SortedDictionary <string, string>();

            foreach (KeyValuePair <string, string> attribute in Attributes)
            {
                attrs.Add(attribute.Key, attribute.Value);
            }

            if (!Attributes.ContainsKey("type"))
            {
                attrs.Add("type", InputType);
            }
            attrs.Add("name", Name);
            if (!String.IsNullOrEmpty(ID))
            {
                attrs.Add("id", ID);
            }


            if (DesignMode)
            {
                // Use a dummy value in design mode
                attrs.Add("value", "TextBox");
            }
            else
            {
                string attemptedValue = (string)GetModelStateValue(Name, typeof(string));

                if (attemptedValue != null)
                {
                    // Never format the attempted value since it was already formatted in the previous request
                    attrs.Add("value", attemptedValue);
                }
                else
                {
                    // Use an explicit value attribute if it is available. Otherwise get it from ViewData.
                    string attributeValue;
                    Attributes.TryGetValue("value", out attributeValue);
                    object rawValue = attributeValue ?? ViewData.Eval(Name);
                    string stringValue;

                    if (String.IsNullOrEmpty(Format))
                    {
                        stringValue = Convert.ToString(rawValue, CultureInfo.CurrentCulture);
                    }
                    else
                    {
                        stringValue = String.Format(CultureInfo.CurrentCulture, Format, rawValue);
                    }

                    // The HtmlTextWriter will automatically encode this value
                    attrs.Add("value", stringValue);
                }

                // If there are any errors for a named field, we add the CSS attribute.
                ModelState modelState = GetModelState();
                if ((modelState != null) && (modelState.Errors.Count > 0))
                {
                    string currentValue;

                    if (attrs.TryGetValue("class", out currentValue))
                    {
                        attrs["class"] = HtmlHelper.ValidationInputCssClassName + " " + currentValue;
                    }
                    else
                    {
                        attrs["class"] = HtmlHelper.ValidationInputCssClassName;
                    }
                }
            }

            foreach (KeyValuePair <string, string> attribute in attrs)
            {
                writer.AddAttribute(attribute.Key, Convert.ToString(attribute.Value, CultureInfo.CurrentCulture));
            }

            writer.RenderBeginTag(HtmlTextWriterTag.Input);

            writer.RenderEndTag();
        }
        public override void Execute()
        {
            #line 1 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"

            var height     = ViewData.Eval("height") != null ? (int)ViewData.Eval("height") : 340;
            var autoresize = ViewData.Eval("autoresize") != null ? (bool)ViewData.Eval("autoresize") : true;


            #line default
            #line hidden
            WriteLiteral("\r\n<script");

            WriteLiteral(" type=\"text/javascript\"");

            WriteAttribute("src", Tuple.Create(" src=\"", 221), Tuple.Create("\"", 279)
                           , Tuple.Create(Tuple.Create("", 227), Tuple.Create <System.Object, System.Int32>(Href("~/manager/assets.ashx/vendor/tiny_mce/tinymce.min.js")
                                                                                                            , 227), false)
                           );

            WriteLiteral("></script>\r\n<script");

            WriteLiteral(" type=\"text/javascript\"");

            WriteLiteral(">\r\n\ttinymce.init({\r\n\t\tmode: \'specific_textareas\',\r\n\t\teditor_selector: \"editor\",\r\n" +
                         "\t\tconvert_urls: false,\r\n\t\tplugins: [\r\n\t\t\"");


            #line 12 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"
            Write(autoresize ? "autoresize" : "");


            #line default
            #line hidden
            WriteLiteral(" autolink code hr paste link\"\r\n\t\t],\r\n\t\twidth: \"100%\",\r\n\t\theight: \"");


            #line 15 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"
            Write(height);


            #line default
            #line hidden
            WriteLiteral("\",\r\n");


            #line 16 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"


            #line default
            #line hidden

            #line 16 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"
            if (autoresize)
            {
            #line default
            #line hidden
                WriteLiteral("\t\t\t");

                WriteLiteral("autoresize_min_height: 340,");

                WriteLiteral("\r\n");


            #line 18 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("\t\tmenubar: false,\r\n\t\tstatusbar: false,\r\n\t\tcontent_css: \"");


            #line 21 "..\..\Areas\Manager\Views\Shared\Partial\Editor.cshtml"
            Write(Url.Content("~/manager/assets.ashx/css/editor.min.css"));


            #line default
            #line hidden
            WriteLiteral("\",\r\n\t\ttoolbar: \"bold italic underline | bullist numlist hr | formatselect removef" +
                         "ormat | cut copy paste | link | code\",\r\n\t});\r\n</script>\r\n");
        }