我用Web API 2创建了一个新的MVC5项目,然后我从NuGet添加了Ninject.MVC3包.
构造函数注入适用于MVC5控制器,但在尝试将其与Web API控制器一起使用时出现错误.
尝试创建"UserProfileController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.
工作MVC5控制器的构造函数:
public class HomeController : Controller
{
private IMailService _mail;
private IRepository _repo;
public HomeController(IMailService mail, IRepository repo)
{
_mail = mail;
_repo = repo;
}
}
Run Code Online (Sandbox Code Playgroud)
非工作Web API控制器的构造函数:
public class UserProfileController : ApiController
{
private IRepository _repo;
public UserProfileController(IRepository repo)
{
_repo = repo;
}
}
Run Code Online (Sandbox Code Playgroud)
下面是完整的NinjectWebCommon.cs文件:
[assembly: WebActivator.PreApplicationStartMethod(typeof(DatingSite.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(DatingSite.App_Start.NinjectWebCommon), "Stop")]
namespace DatingSite.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using DatingSite.Services;
using DatingSite.Data;
public static class …Run Code Online (Sandbox Code Playgroud) 我有两个指令
app.directive('panel1', function ($compile) {
return {
restrict: "E",
transclude: 'element',
compile: function (element, attr, linker) {
return function (scope, element, attr) {
var parent = element.parent();
linker(scope, function (clone) {
parent.prepend($compile( clone.children()[0])(scope));//cause error.
// parent.prepend(clone);// This line remove the error but i want to access the children in my real app.
});
};
}
}
});
app.directive('panel', function ($compile) {
return {
restrict: "E",
replace: true,
transclude: true,
template: "<div ng-transclude ></div>",
link: function (scope, elem, attrs) {
} …Run Code Online (Sandbox Code Playgroud) 我希望有一个函数来通过获取包含属性名称和排序方向的字符串作为输入来对对象数组进行排序.我需要这样的东西:
var myArray = [{name:"A", age: 30}, {name:"B", age:20}, {name:"C", age:20}];
var strSort = "age asc, name desc";
var sortedArray = customSortFuntion(myArray,strSort);
//sortedArray == [{name:"C", age:20}, {name:"B", age:20},{name:"A", age: 30}]
function customSortFuntion(myArray,strSort)
{
//return sorted by age asc and sorted by name desc etc..??
}
Run Code Online (Sandbox Code Playgroud) 我在我的web api项目中有一个全局异常处理程序.这种方法很好,除非通过lambda表达式引发异常.我在下面提供了示例代码:
[HttpGet]
public IHttpActionResult Test()
{
//Throw new Exception();// this exception is handled by my ExceptionHandler
var list = new List<int>();
list.Add(1);
IEnumerable<int> result = list.Select(a => GetData(a));
return Ok(result);
}
private static int GetData(int a)
{
throw new Exception();//This is not handled by my global exception handler
}
Run Code Online (Sandbox Code Playgroud)
这是我的全局异常处理程序
public class ExceptionHandlerAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
//Do something
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的WebApiConfig类中注册它
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute( …Run Code Online (Sandbox Code Playgroud) 我有一个信号服务器2.0服务器应该服务于多个域..因此需要在我的服务器中启用CORS.我将iis7.5用作Web服务器.我在Startup我的项目方法中启用了CORS,如下所示
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
// Setup the CORS middleware to run before SignalR.
// By default this will allow all origins. You can
// configure the set of origins and/or http verbs by
// providing a cors options with a different policy.
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
// You can enable JSONP by uncommenting line below.
// JSONP requests are insecure but some older browsers (and some
// versions of …Run Code Online (Sandbox Code Playgroud) 我有html如下,这是一个jsbin帖子.
我希望蓝色和红色div在xs大小上交换它们的位置.
<div class="row">
<div class="col-xs-12 col-sm-6" style="background-color:red;">
red
</div>
<div class="col-xs-12 col-sm-6" style="background-color:blue;">
blue
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
是否可以在bootstrap 3.0中更改移动大小的列顺序.