当前位置: 首页>>代码示例>>C#>>正文


C# FormDataCollection.ReadAsNameValueCollection方法代码示例

本文整理汇总了C#中FormDataCollection.ReadAsNameValueCollection方法的典型用法代码示例。如果您正苦于以下问题:C# FormDataCollection.ReadAsNameValueCollection方法的具体用法?C# FormDataCollection.ReadAsNameValueCollection怎么用?C# FormDataCollection.ReadAsNameValueCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FormDataCollection的用法示例。


在下文中一共展示了FormDataCollection.ReadAsNameValueCollection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post

        //public Car Post(Car car) {
        //    if (null != car) {
        //        car.Id = 1;
        //        return car;
        //    }
        //    throw new HttpResponseException(new HttpResponseMessage() {
        //        StatusCode = HttpStatusCode.BadRequest,
        //        ReasonPhrase = "Car data must contain at least one value."
        //    });
        //}

        public Car Post(FormDataCollection carFormData) {
            var carFormKeyValues = carFormData.ReadAsNameValueCollection();
            var car = new Car() {
                Make = carFormKeyValues["Make"],
                Model = carFormKeyValues["Model"],
                Price = Convert.ToSingle(carFormKeyValues["Price"]),
                Year = Convert.ToInt32(carFormKeyValues["Year"])
            };
            return car;
        }
开发者ID:tugberkugurlu,项目名称:ProWebAPI.Samples,代码行数:21,代码来源:CarsController.cs

示例2: Put

        public void Put(FormDataCollection form)
        {
            // Manually parse up the form b/c of the muni & county split stuff
            // TODO: make a custom formatter
            int projectVersionId = Convert.ToInt32(form.Get("ProjectVersionId"));
            string year = form.Get("Year");
            //Get the existing model from the datagbase
            LocationModel model = SurveyRepository.GetProjectLocationModel(projectVersionId, year);
            //Update values
            model.Limits = form.Get("Limits");
            model.FacilityName = form.Get("FacilityName");
            int testOut = 0;
            Int32.TryParse(form.Get("RouteId"), out testOut);
            model.RouteId = testOut;

            //parse out the county & muni shares stuff...
            var nvc = form.ReadAsNameValueCollection();
            Dictionary<int, CountyShareModel> countyShares = ControllerBase.ExtractCountyShares(nvc);
            Dictionary<int, MunicipalityShareModel> muniShares = ControllerBase.ExtractMuniShares(nvc);

            //Send updates to repo
            try
            {
                SurveyRepository.UpdateProjectLocationModel(model, projectVersionId);
                SurveyRepository.CheckUpdateStatusId(SurveyRepository.GetProjectBasics(projectVersionId));
                //Update the county shares
                foreach (CountyShareModel m in countyShares.Values)
                {
                    SurveyRepository.UpdateCountyShare(m);
                }
                //Update the muni shares
                foreach (MunicipalityShareModel m in muniShares.Values)
                {
                    SurveyRepository.UpdateMunicipalityShare(m);
                }
                //Ok, we're good.
            }
            catch (Exception ex)
            {
                Logger.WarnException("Could not update Survey Location", ex);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = ex.Message });
            }
        }
开发者ID:ccpowell,项目名称:mvc4-examples,代码行数:43,代码来源:SurveyLocationController.cs

示例3: CaseSensitive

        public void CaseSensitive()
        {
            FormDataCollection form = new FormDataCollection(new Uri("http://foo.com/?x=1&X=2"));

            NameValueCollection nvc = form.ReadAsNameValueCollection();

            Assert.Equal(2, nvc.Count);
            Assert.Equal("1", nvc.Get("x"));
            Assert.Equal("2", nvc.Get("X"));
        }
开发者ID:steven-r,项目名称:aspnetwebstack,代码行数:10,代码来源:FormDataCollectionTests.cs

示例4: ToNameValueCollection

        public void ToNameValueCollection()
        {
            FormDataCollection form = new FormDataCollection(new Uri("http://foo.com/?x=1a&y=2&x=1b&=ValueOnly&KeyOnly"));

            NameValueCollection nvc = form.ReadAsNameValueCollection();

            // y=2
            // x=1a;x=1b
            // =ValueOnly
            // KeyOnly
            Assert.Equal(4, nvc.Count);
            Assert.Equal(new string[] { "1a", "1b"}, nvc.GetValues("x"));
            Assert.Equal("1a,1b", nvc.Get("x"));
            Assert.Equal("2", nvc.Get("y"));
            Assert.Equal("", nvc.Get("KeyOnly"));            
            Assert.Equal("ValueOnly", nvc.Get(""));
        }
开发者ID:steven-r,项目名称:aspnetwebstack,代码行数:17,代码来源:FormDataCollectionTests.cs

示例5: ParseCookieSegment

        private static bool ParseCookieSegment(CookieHeaderValue instance, string segment)
        {
            if (String.IsNullOrWhiteSpace(segment))
            {
                return true;
            }

            string[] nameValue = segment.Split(nameValueSeparator, 2);
            if (nameValue.Length < 1 || String.IsNullOrWhiteSpace(nameValue[0]))
            {
                return false;
            }

            string name = nameValue[0].Trim();
            if (String.Equals(name, ExpiresToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                DateTimeOffset expires;
                if (FormattingUtilities.TryParseDate(value, out expires))
                {
                    instance.Expires = expires;
                    return true;
                }
                return false;
            }
            else if (String.Equals(name, MaxAgeToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                int maxAge;
                if (FormattingUtilities.TryParseInt32(value, out maxAge))
                {
                    instance.MaxAge = new TimeSpan(0, 0, maxAge);
                    return true;
                }
                return false;
            }
            else if (String.Equals(name, DomainToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Domain = GetSegmentValue(nameValue, null);
                return true;
            }
            else if (String.Equals(name, PathToken, StringComparison.OrdinalIgnoreCase))
            {
                instance.Path = GetSegmentValue(nameValue, DefaultPath);
                return true;
            }
            else if (String.Equals(name, SecureToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return false;
                }
                instance.Secure = true;
                return true;
            }
            else if (String.Equals(name, HttpOnlyToken, StringComparison.OrdinalIgnoreCase))
            {
                string value = GetSegmentValue(nameValue, null);
                if (!String.IsNullOrWhiteSpace(value))
                {
                    return false;
                }
                instance.HttpOnly = true;
                return true;
            }
            else
            {
                string value = GetSegmentValue(nameValue, null);

                // We read the cookie segment as form data
                try
                {
                    FormDataCollection formData = new FormDataCollection(value);
                    NameValueCollection values = formData.ReadAsNameValueCollection();
                    CookieState cookie = new CookieState(name, values);
                    instance.Cookies.Add(cookie);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:85,代码来源:CookieHeaderValue.cs

示例6: PostFormData

        // Post form data
        public string PostFormData(FormDataCollection a)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            try
            {
                NameValueCollection collection = a.ReadAsNameValueCollection();
            }
            catch (InvalidOperationException ex)
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                response.Content = new StringContent(ex.Message);
                throw new HttpResponseException(response);
            }

            return "success from PostFormData";
        }
开发者ID:ssswagatss,项目名称:aspnetwebstack,代码行数:21,代码来源:MaxHttpCollectionKeyTests.cs


注:本文中的FormDataCollection.ReadAsNameValueCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。