小编Alb*_*orz的帖子

MVC5,Web API 2和Ninject

我用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)

ninject asp.net-web-api asp.net-mvc-5

72
推荐指数
4
解决办法
5万
查看次数

在模板中非法使用ngTransclude指令

我有两个指令

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)

angularjs angularjs-directive

22
推荐指数
2
解决办法
3万
查看次数

将指定排序条件的对象数组排序为字符串

我希望有一个函数来通过获取包含属性名称和排序方向的字符串作为输入来对对象数组进行排序.我需要这样的东西:

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)

javascript arrays sorting

6
推荐指数
1
解决办法
215
查看次数

当通过lambda表达式引发异常时,如何在asp.net web api中全局处理异常

我在我的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)

c# asp.net lambda asp.net-web-api

6
推荐指数
1
解决办法
512
查看次数

跨域不适用于signalr 2.0

我有一个信号服务器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)

c# asp.net signalr

5
推荐指数
1
解决办法
7060
查看次数

更改bootstrap 3网格中的列顺序

我有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中更改移动大小的列顺序.

css html5 twitter-bootstrap twitter-bootstrap-3

1
推荐指数
1
解决办法
1816
查看次数