コード例 #1
0
 /// <summary>
 /// Binds specified form data to model.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public void Bind <T>(ModelBinderEventArgs <T> args)
 {
     if (args.Context.Request.ContentType.Contains("application/x-www-form-urlencoded"))
     {
         args.SetModel(
             ListToModelParser.Parse <T>(args.Context.Form.Select(x => new KeyValuePair <string, string[]>(x.Key, x.Value)).ToList()));
     }
 }
コード例 #2
0
 /// <summary>
 /// Binds specified HTTP query to model.
 /// </summary>
 /// <typeparam name="T">Model type</typeparam>
 /// <param name="args">The <see cref="ModelBinderEventArgs{T}" /> instance containing the event data.</param>
 public void Bind <T>(ModelBinderEventArgs <T> args)
 {
     if (args.Context.Request.Method == "GET")
     {
         args.SetModel(
             ListToModelParser.Parse <T>(
                 args.Context.Query.Select(x => new KeyValuePair <string, string[]>(x.Key, x.Value)).ToList()));
     }
 }
コード例 #3
0
        /// <summary>
        /// Binds specified HTTP query to model asynchronously.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public Task BindAsync <T>(ModelBinderEventArgs <T> args)
        {
            if (args.Context.Request.Method == "GET")
            {
                args.SetModel(ListToModelParser.Parse <T>(args.Context.Query.Select(x => new KeyValuePair <string, string[]>(x.Key, x.Value))
                                                          .ToList()));
            }

            return(Task.CompletedTask);
        }
コード例 #4
0
        /// <summary>
        /// Binds specified form data to model asynchronously.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async Task BindAsync <T>(ModelBinderEventArgs <T> args)
        {
            if (args.Context.Request.ContentType == null || !args.Context.Request.ContentType.Contains("application/x-www-form-urlencoded"))
            {
                return;
            }

            await args.Context.ReadFormAsync();

            args.SetModel(ListToModelParser.Parse <T>(args.Context.Form.Select(x => new KeyValuePair <string, string[]>(x.Key, x.Value)).ToList()));
        }