遇到标题中所说的问题原因是使用 jQuery AJAX 以 POST 方式调用 Asp.Net Web API 。解决办法请看以下代码中有注释的部分。publicstaticclass WebApiConfig
{publicstaticvoid Register(HttpConfiguration config){config.Formatters.Clear();config.Formatters.Add( new JsonMediaTypeFormatter {SerializerSettings = {ContractResolver = new DefaultContractResolver()}} );// 添加以下语句即可解决问题config.Formatters.Add( ...
复制代码 代码如下:String.Format("{0} world!","hello") //将输出 hello world!,没有问题,但是只要在第一个参数的任意位置加上一个大括号: String.Format("{0} wo{rld!","hello") //就会产生一个异常,异常信息是:Input string was not in a correct format. //解决办法:String.Format("{0} wo{{rld!","hello") //or String.Format("{0} wo{1}rld!","hello","{") //它们都将输出 hello wo{rld!原文:http://www.jb51.net/art...
1、创建对应configuration的App.config文件,比如:App.Debug.config、App.Release.config。2、编辑项目文件,将App.*.config文件的Build Action修改为Content,参考如下:<Content Include="App.config"/><Content Include="App.Debug.config"><DependentUpon>App.config</DependentUpon></Content><Content Include="App.Publish.config"><DependentUpon>App.config</DependentUpon></Content><Content Include="App.Release.con...
1. 综述
大多数程序里都会在Web.config里设置参数,并且在部署的时候需要更改。每次都手工更改这些配置很乏味,也容易出错。该章节将会告诉你如果通过自动化更新Web.config文件来避免这些问题。
2. Web.config Transformations 与Web Deploy Parameters
有2种方式来自动化更新Web.config文件的设置:Web.config transformations和Web Deploy parameters。Web.config transformation文件包含部署时需要更新的XML标记 。你可以为不同...
本文实例讲述了Gridview利用DataFormatString属性设置数据格式的方法。分享给大家供大家参考,具体如下:
首先把Gridview的AutoGenerateColumns属性设为False(默认是False),DataField选择相应的字段,特别需要注意的是要把需要设置的字段的HtmlEncode属性设置为False,否则所设置的格式将无法显示,然后就可以设置每个字段的 DataFormatString属性来输出不同的格式了。
DataFormatString 属性语法如下: {A:B}
如:DataFormatSt...
DataFormatString是很多Asp.Net控件都有的属性,如GridView等等,下面简单介绍一下这个属性。 DataFormatString 属性语法如下: DataFormatString="{0:格式字符串}" 我们知道在DataFormatString 中的 {0} 表示数据本身,而在冒号后面的格式字符串代表所们希望数据显示的格式;另外在指定的格式符号后可以指定小数所要显示的位数。例如原来的数据为 「1.56」,若格式设定为 {0:N1},则输出为「1.5」。 设定BoundField的DataFormatString...
症状:在GridView绑定日期格式的时候,数据库中的日期为2008-07-04,而GridView显示的是2007-07-04 000000。、 解决办法:想把这后面这多余的零去掉的话在绑定时间的那一列源码后面加上一句话就可以了,如下红色的部分 代码如下:<asp:BoundField DataField="BeginDate" HeaderText="开始时间" DataFormatString="{0:d}" htmlencode="false" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" > 如果哪里...
代码如下:String.Format("{0} world!","hello") //将输出 hello world!,没有问题,但是只要在第一个参数的任意位置加上一个大括号: String.Format("{0} wo{rld!","hello") //就会产生一个异常,异常信息是:Input string was not in a correct format. //解决办法:String.Format("{0} wo{{rld!","hello") //or String.Format("{0} wo{1}rld!","hello","{") //它们都将输出 hello wo{rld!
在.net中,查了半天msdn,发现使用DataFormatString是可以实现这个功能的,但是怎么设置就不起作用,最后发现,由于2.0出于安全性的考虑,还要同时设置HtmlEncode = false,才能够使DataFormatString生效. 留个记号,下次用的时候,就不用浪费N多时间了. 还有,DataFormatString = "{0:F}",是默认格式,显示两位小数,如果需要显示的小数位数为其他值,DataFormatString = "{0:Fn}"即可. 代码如下:DataFormatString="{0:格式字符串}" 在DataFor...
假设我向API发送了以下请求:POST http://localhost:4940/api/cars HTTP/1.1
User-Agent: Fiddler
Host: localhost:4940
Content-Type: application/json
Content-Length: 44{"Make":"Make1","Year":2010,"Price":10732.2}而且我有以下Car类定义:public class Car {public int Id { get; set; }[Required][StringLength(20)]public string Make { get; set; }[Required][StringLength(20)]public string Model { get; set; }publi...
我的ASP.NET MVC应用程序有一个Html Helper文件.他们中的大多数只返回一个格式化的字符串.
以下是我的一个格式化字符串助手的示例:public static string Label(this HtmlHelper helper, string @for, string text)
{return string.Format("<label for \"{0}\">{1}</label>", @for, text);
}这是一个TagBuilder版本,它给出了与上面相同的结果:public static string Label(this HtmlHelper helper, string @for, string text)
{var...