/// <summary>
        /// Process a tag
        /// </summary>
        /// <param name="context">Context with all html tag information</param>
        public void Process(FormItemAdapterContext context)
        {
            if (context.Metadata.PropertyName!= "Age")
                return;

            context.TagBuilder.MergeAttribute("disabled", "disabled");


            var  scriptTag = new NestedTagBuilder("script");
            scriptTag.MergeAttribute("type", "text/javascript");
            scriptTag.InnerHtml =string.Format(
                @"$(function(){{ 
    var $slider = $('<div id=""slider""></div>').insertAfter($('#{0}'));
    $slider.slider({{
        min: 0, 
        max:110, 
        value: {1},
		slide: function( event, ui ) {{
			$('#{0}').val(ui.value);
        }}

    }});
}});", context.TagBuilder.Attributes["id"], context.TagBuilder.Attributes["value"]);

            var div = new NestedTagBuilder("div");
            div.AddChild(context.TagBuilder);
            div.AddChild(scriptTag);
            context.TagBuilder = div;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Begins the form.
        /// </summary>
        /// <param name="actionName">Name of the action.</param>
        /// <param name="controllerName">Name of the controller.</param>
        /// <param name="method">The method.</param>
        /// <param name="routeValues">The route values.</param>
        /// <param name="htmlAttributes">The HTML attributes.</param>
        /// <returns></returns>
        public virtual MvcForm BeginForm(string actionName     = null, string controllerName         = null,
                                         FormMethod method     = FormMethod.Post, object routeValues = null,
                                         object htmlAttributes = null)
        {
            var routes     = new RouteValueDictionary(routeValues);
            var attributes = new RouteValueDictionary(htmlAttributes);
            var url        = UrlHelper.GenerateUrl(null, actionName, controllerName, routes, RouteCollection,
                                                   ViewContext.RequestContext, true);

            var tagBuilder = new NestedTagBuilder("form");

            tagBuilder.MergeAttributes(attributes);
            tagBuilder.MergeAttribute("action", url);
            tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
            var item = InvokeHtmlTagAdapters(new[] { tagBuilder }).First();

            var httpResponse = ViewContext.HttpContext.Response;

            httpResponse.Write(item.ToString(TagRenderMode.StartTag));
            return(new MvcForm(ViewContext));
        }
 public void AddChild(NestedTagBuilder builder)
 {
     _children.AddLast(builder);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormItemAdapterContext"/> class.
 /// </summary>
 /// <param name="tagBuilder">Generated tag builder.</param>
 /// <param name="metadata">Model metadata.</param>
 public FormItemAdapterContext(NestedTagBuilder tagBuilder, ModelMetadata metadata)
     : base(tagBuilder)
 {
     Metadata = metadata;
 }
Ejemplo n.º 5
0
 public void AddChild(NestedTagBuilder builder)
 {
     _children.AddLast(builder);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormItemAdapterContext"/> class.
 /// </summary>
 /// <param name="tagBuilder">Generated tag builder.</param>
 /// <param name="metadata">Model metadata.</param>
 public FormItemAdapterContext(NestedTagBuilder tagBuilder, ModelMetadata metadata)
     : base(tagBuilder)
 {
     Metadata = metadata;
 }