我在ASP .NET MVC 4 RC中使用Web API,我有一个方法,它采用具有可为空的DateTime属性的复杂对象.我希望从查询字符串中读取输入的值,所以我有这样的事情:
public class MyCriteria
{
public int? ID { get; set; }
public DateTime? Date { get; set; }
}
[HttpGet]
public IEnumerable<MyResult> Search([FromUri]MyCriteria criteria)
{
// Do stuff here.
}
Run Code Online (Sandbox Code Playgroud)
如果我在查询字符串中传递标准日期格式(例如01/15/2012),这很有效:
http://mysite/Search?ID=1&Date=01/15/2012
Run Code Online (Sandbox Code Playgroud)
但是,我想为DateTime指定一个自定义格式(可能是MMddyyyy)...例如:
http://mysite/Search?ID=1&Date=01152012
Run Code Online (Sandbox Code Playgroud)
我已经尝试应用自定义模型绑定器,但我没有运气只将其应用于DateTime对象.我试过的ModelBinderProvider看起来像这样:
public class DateTimeModelBinderProvider : ModelBinderProvider
{
public override IModelBinder GetBinder(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType == typeof(DateTime) || bindingContext.ModelType == typeof(DateTime?))
{
return new DateTimeModelBinder();
}
return null;
}
}
// In the Global.asax
GlobalConfiguration.Configuration.Services.Add(typeof(ModelBinderProvider), new DateTimeModelBinderProvider()); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用Katana来公开自托管WebAPI服务的应用程序.我想管理内容的方式与IIS在单个网站下允许多个应用程序的方式类似.
例如,我可能有三个包含web api内容的文件夹:
这些文件夹中的每一个都是独立的应用程序,包括web.config,控制器,路由等.
我可以为每个实例生成一个新的Owin实例,但这需要单独的端口.使用IIS,我可以配置单独的应用程序,以便http:// localhost:8080/App1将路由到第一个应用程序,http:// localhost:8080/App2将路由到第二个应用程序,依此类推.与Owin/Katana有什么相似之处吗?
我想在 .NET Core 2.0 应用程序和 SQL Server CLR 过程之间共享库。我尝试将共享逻辑放入以下项目类型中:
.NET 标准库
.NET 标准库可以从 .NET Core 项目使用,并且我可以添加来自 SQL Server 项目的引用,但是,不能在 CLR 过程中引用类:

便携式类库
可从 CLR 过程中引用可移植类库。PCL 可以选择以 ASP.NET Core 1.0 为目标,但我无法找到以 .NET Core 2.0 为目标的方法。当我从 .NET Core 2.0 项目引用此库时,出现以下编译错误:
Project PortableLibrary1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Project PortableLibrary1 supports: dotnet5.0 (.NETPlatform,Version=v5.0)
Run Code Online (Sandbox Code Playgroud)
是否有其他选项可以在 .NET Core 2.0 和 SQL Server CLR 之间共享库?
我想创建一个循环遍历数组的自定义元素,并将其应用于数组中的每个项目.例如,自定义元素的视图模板将包含以下内容:
<div repeat.for="i of items">
<div with.bind="i">
<slot></slot>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我删除repeat.for和with.bind属性时,插槽显示一次.有没有办法让它重复列表中的每个项目?