本文整理汇总了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;
}
示例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 });
}
}
示例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"));
}
示例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(""));
}
示例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;
}
}
}
示例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";
}