小编whe*_*ell的帖子

使用AngularJS从ASP.NET Web API方法下载文件

在我的Angular JS项目中,我有一个<a>锚标记,当单击它时会GET向返回文件的WebAPI方法发出HTTP 请求.

现在,我希望在请求成功后将文件下载到用户.我怎么做?

锚标记:

<a href="#" ng-click="getthefile()">Download img</a>
Run Code Online (Sandbox Code Playgroud)

AngularJS:

$scope.getthefile = function () {        
    $http({
        method: 'GET',
        cache: false,
        url: $scope.appPath + 'CourseRegConfirm/getfile',            
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        }
    }).success(function (data, status) {
        console.log(data); // Displays text data if the file is a text file, binary if it's an image            
        // What should I write here to download the file I receive from the WebAPI method?
    }).error(function (data, status) {
        // ...
    });
}
Run Code Online (Sandbox Code Playgroud)

我的WebAPI方法: …

html javascript c# asp.net-web-api angularjs

132
推荐指数
3
解决办法
19万
查看次数

Where().Count()和Count()之间的区别

using (DBEntities db = new DBEntities())
{
   var employeeAgedAbove30 = db.Employees.Where(s => s.Age > 30).Count(); // Method 1

   employeeAgedAbove30 = db.Employees.Count(s => s.Age > 30); // Method 2

}
Run Code Online (Sandbox Code Playgroud)

考虑上面的例子,我列出了30岁以上的员工.

方法1和方法2有什么区别?你更喜欢哪一个?为什么?

c# linq entity-framework

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

nopcommerce中的插件和小部件之间的区别

我想在每个产品页面中显示一个文本框和一个按钮。客户将在文本框中输入他/她的城市名称,然后单击按钮以了解他/她的城市是否可以送货。

我了解到我应该创建一个插件/小部件。但是我对使用哪个感到有些困惑?插入?还是小部件?

nopcommerce中的插件和小部件之间有什么区别?我在这里应该使用什么?

c# nopcommerce asp.net-mvc-4

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

将json数据发布到angularjs中的WebAPI方法

$scope.items = {2: true, 4: true, 5: true, 7: true, 9: true, 10: true, 11: true };
Run Code Online (Sandbox Code Playgroud)

如何使用angularjs的$ http将上述json数据发布到以下WebAPI方法?

[Authorize]
[HttpPost]
[Route("moveemployees")]
public HttpResponseMessage MoveEmployees(Dictionary<decimal, bool> employeeList)     
    {
         // employeeList doesn't contain any items after the post
         return Request.CreateResponse(HttpStatusCode.OK);
    }
Run Code Online (Sandbox Code Playgroud)

我试过了 :

$http({
        method: 'POST',
        cache: false,
        url: $scope.appPath + 'Employee/moveemployees',
        data: { employeeList : $scope.items },
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
           }
        }).success(function (data, status) {
            $scope.infos.push('Employees Moved Successfully');
            $scope.errors = [];
        }).error(function (data, status) {                
     });
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

c# json asp.net-web-api angularjs

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

自定义授权过滤器中的访问会话

如何Session["userName"]在我的自定义授权过滤器中使用?

void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{            
    string userName = Session["userName"]; // Shows error "The name 'Session' does not exist in the current context              

    base.OnAuthorization(filterContext);
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4

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