小编Mou*_*ark的帖子

具有多个参数的Web API路由

我正在尝试找出如何为以下Web API控制器进行路由:

public class MyController : ApiController
{
    // POST api/MyController/GetAllRows/userName/tableName
    [HttpPost]
    public List<MyRows> GetAllRows(string userName, string tableName)
    {
        ...
    }

    // POST api/MyController/GetRowsOfType/userName/tableName/rowType
    [HttpPost]
    public List<MyRows> GetRowsOfType(string userName, string tableName, string rowType)
    {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

目前,我正在使用此路由到URL:

routes.MapHttpRoute("AllRows", "api/{controller}/{action}/{userName}/{tableName}",
                    new
                    {
                        userName= UrlParameter.Optional,
                        tableName = UrlParameter.Optional
                    });

routes.MapHttpRoute("RowsByType", "api/{controller}/{action}/{userName}/{tableName}/{rowType}",
                    new
                    {
                        userName= UrlParameter.Optional,
                        tableName = UrlParameter.Optional,
                        rowType= UrlParameter.Optional
                    });
Run Code Online (Sandbox Code Playgroud)

但目前只有第一种方法(有2个参数)正在工作.我是在正确的路线上,还是我的URL格式或路由完全错误?路由对我来说似乎是黑魔法......

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

25
推荐指数
2
解决办法
8万
查看次数

如何使用UserManager在IdentityUser上加载导航属性

我已经扩展IdentityUser为包含用户地址的导航属性,但是在获取用户时UserManager.FindByEmailAsync,不会填充导航属性.ASP.NET Identity Core是否有某种方法来填充Entity Framework的导航属性Include(),或者我是否必须手动执行此操作?

我已经设置了这样的导航属性:

public class MyUser : IdentityUser
{
    public int? AddressId { get; set; }

    [ForeignKey(nameof(AddressId))]
    public virtual Address Address { get; set; }
}

public class Address
{
    [Key]
    public int Id { get; set; }
    public string Street { get; set; }
    public string Town { get; set; }
    public string Country { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core asp.net-core-identity

24
推荐指数
4
解决办法
3840
查看次数

在MVC5中使用Razor渲染部分视图

我试图在MVC5中使用Razor进行局部视图渲染.我用的时候

@{ Html.RenderPartial("ViewName", model); }
Run Code Online (Sandbox Code Playgroud)

我得到解析器错误:

"@"字符后出现意外的"{".一旦进入代码块的主体(@if {},@ {}等),您就不需要使用"@ {"来切换到代码.

当我删除{},即:

@Html.RenderPartial("ViewName", model);
Run Code Online (Sandbox Code Playgroud)

我收到编译错误

无法将类型'void'隐式转换为'object'.

我究竟做错了什么?

asp.net-mvc razor asp.net-mvc-5

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

在ES6中导入和使用d3及其子模块的正确方法是什么?

我正在尝试在Vue.js项目中使用一些d3包和NPM进行包管理.我试图弄清楚我遇到的问题,但无法在那里复制问题 - 代码完全按照应有的方式工作.

我正在尝试确定在JSFiddle中运行的代码与在我的应用程序中运行的代码之间的差异(除了显而易见的事实,即我没有在小提琴中运行Vue.js),最重要的是我如何导入我的额外内容库.在小提琴中我添加了从CDNJS相关库的链接,而在我的应用程序中,我正在使用NPM和import.这就是使用dc基于许多d3功能构建的图表.我对图表组件的完整导入是:

import dc from 'dc'
import crossfilter from 'crossfilter2'
import * as time from 'd3-time'
import * as scale from 'd3-scale'
Run Code Online (Sandbox Code Playgroud)

我没有使用基本d3模块的任何功能.

有问题的小提琴在这里:https://jsfiddle.net/y1qby1xc/10/

npm d3.js ecmascript-6 dc.js es6-modules

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

删除 SQL Server 2005 中的条目 - 将 varchar 值转换为数据类型 int 时转换失败

我在 SQL Server 2005 中手动编辑表并尝试删除单个记录,但不断收到以下错误:

将 varchar 值“D”转换为数据类型 int 时转换失败

int 或其他列都不包含值“D”,所以我对此感到非常困惑。我已经检查了数据库中该条目的主键是外键的所有表,但也没有任何内容。

有什么建议么?

sql sql-server sql-server-2005

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

将html响应内容的charset设置为1252

我正在尝试在HTTP响应中发送一些在Windows 1252中编码的数据(它是一个CSV文件),但在某些地方,它会被重新编码为UTF-8(无BOM).如何确保数据保持正确的编码?

var sb = new StringBuilder();
// Build the file from windows-1252 strings in the sb...
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("filename=\"{0}\".csv", fileName));
HttpContext.Current.Response.ContentType = "text/csv;charset=windows-1252";
HttpContext.Current.Response.Charset = "windows-1252";
HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud)

c# httpresponse character-encoding windows-1252

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

How to import two exports with the same name from the same file

I have a Typescript file that looks like this:

export interface Prisma {
    // Members
}

export const Prisma = (): Prisma => {
    // returns a object with of type Prisma
};
Run Code Online (Sandbox Code Playgroud)

Given that both of these entities have the same name in the same file (which I can't change), how can I import the interface in another file? Writing

import Prisma from './myFile';
Run Code Online (Sandbox Code Playgroud)

always imports the exported const, never the exported interface.

typescript

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

jQuery属性选择器无法识别的表达式错误

我正在使用以下代码从导航无序列表中选择当前页面的列表项,但我一直收到无法识别的表达式错误 'a[href$="{server-relative URL}"]'

我检查了其他问题提到的匹配引号/括号,链接不包含通常/ & ? %的字符我正在使用的代码是:

$(document).ready(function() {
    var pathname = window.location.pathname;
    var selector = "'a[href$=\"" + pathname + "\"]'";
    var listItem = $(selector).parent().parent();
    listItem.addClass('selected');
});
Run Code Online (Sandbox Code Playgroud)

我正在使用jQuery 1.8.2(最新版本).谢谢!

javascript jquery

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

使用EPPlus设置Excel工作表保护

我正在尝试使用EPPlus设置XLSM文件的工作表权限,但似乎我只能设置默认保护级别,没有设置单个保护。作为记录,我正在尝试以编程方式完成本文中的方法1 。这是我正在使用的代码:

using (var p = new ExcelPackage("output.xlsm"))
{
    var ws = p.Workbook.Worksheets["MySheet"];

    // Set some cell values here

    // Filtering, sorting, protection
    ws.Cells[7, 1, 10, 5].AutoFilter = true;
    ws.View.FreezePanes(7, 1);
    ws.ProtectedRanges.Add("FilteredCells", new ExcelAddress(7, 1, 10, 5));

    // Worksheet protection
    ws.Protection.AllowAutoFilter = true;
    ws.Protection.AllowDeleteColumns = false;
    ws.Protection.AllowDeleteRows = false;
    ws.Protection.AllowEditObject = false;
    ws.Protection.AllowEditScenarios = false;
    ws.Protection.AllowFormatCells = false;
    ws.Protection.AllowFormatColumns = false;
    ws.Protection.AllowFormatRows = false;
    ws.Protection.AllowInsertColumns = false;
    ws.Protection.AllowInsertHyperlinks = false;
    ws.Protection.AllowInsertRows = false;
    ws.Protection.AllowPivotTables = false;
    ws.Protection.AllowSelectLockedCells = …
Run Code Online (Sandbox Code Playgroud)

c# excel worksheet epplus

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

当我在 Xcode 中运行“产品”-&gt;“存档”时,会执行哪些“xcodebuild”命令?

我正在尝试从命令行而不是通过 Xcode 构建 IOS 应用程序,这是一场艰苦的斗争。我的项目通过转到“产品”->“存档”在 Xcode 中构建得很好,但是当我尝试在终端中使用 执行我认为相同的操作时xcodebuild,由于缺少一些头文件而失败。

如何了解单击“存档”时实际发生的情况?

或者,如果有人能发现我的错误所在,我认为应该有效的命令是:

xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Beta -destination 'generic/platform=iOS' -archivePath <path to xcarchive file> archive
Run Code Online (Sandbox Code Playgroud)

xcode xcodebuild

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