小编Vin*_*nyG的帖子

如何使用mongo c#driver更新数组/列表中的项目?

随着mongodb的10gen c#驱动程序的最新更新,我想更新我的代码,因此它使用强类型版本.

我之前的电话是:

var update2 = new UpdateBuilder();
var index = album.Ratings.IndexOf(rating);
update2.Set("Ratings." + index + ".Number", number);
update2.Set("Rating", album.Rating);
_session.Db().GetCollection<Album>("Album")
    .Update(Query<Album>.Where(x => x.Id == objId), update2); //this line is working
Run Code Online (Sandbox Code Playgroud)

新的电话会是:

update.Set(x => x.Ratings[index].Number, number);
//update2.Set("Ratings." + index + ".Number", number); previous call
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个例外:

无法确定表达式的序列化信息:(Album x)=> x.Ratings.get_Item(WebApp.Areas.API.Controllers.RatingController + <> c__DisplayClass5.index).Number.

有什么方法可以更新List中的项目吗?

c# mongodb mongodb-.net-driver

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

MVC3模型验证不适用于double

我在MVC中验证了问题,我的模型有双重属性,当我提交10.30或任何带有"."的东西时.在里面它告诉我"价值'10 .30'对价格无效".我做了一些研究,他们说模型验证应该是文化不变的,我认为它可能是问题,因为我的浏览器和服务器是法语但它不应该.

这是我的代码:

[HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "Admin")]
        [ValidateInput(false)]
        public virtual ActionResult Edit(AuctionModel model)
        {
            if (ModelState.IsValid)
            {
                //do the work
            }
            return View(model);
        }

public class AuctionModel
    {
        public string Id { get; set; }
        [Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
        [LocalizedDisplayName("Title")]
        public string Title { get; set; }
        [Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
        [LocalizedDisplayName("Description")]
        public string Description { get; set; }
        [Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
        [LocalizedDisplayName("Photo")]
        public string Photo { get; set; }
        [Required(ErrorMessageResourceType = …
Run Code Online (Sandbox Code Playgroud)

c# data-annotations asp.net-mvc-3

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

如何使用NPOI 2.0保存excel 2010+

我使用NPOI很长一段时间它总是有效但现在我需要使用.xlsx和至少Microsoft Office 2010.它可以工作,但当我尝试打开文件时它说它已损坏我无法修复它.这是我得到的错误:

Repaired Part: /xl/worksheets/sheet1.xml part with XML error.  Load error. Line 1, column 7550.
Repaired Records: Cell information from /xl/worksheets/sheet1.xml part
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

我有这个样本,我仍然遇到同样的问题:http://www.leniel.net/2014/02/npoi2.0-excel-2007-xssfworkbook-and-word-2007-xwpfdocument-support.html#sthash .T7qk6CSv.dpbs

c# excel corrupt xlsx npoi

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

如何使用自定义模型绑定器对路径进行单元测试

我有一个自定义模型绑定器,用于检查用户是否可以访问他要求的文档; 我想知道如何测试使用此自定义绑定器的路径?

我尝试这个测试,但我收到此错误:

MvcContrib.TestHelper.AssertionException:参数'contract'的值不匹配:预期'Domain.Models.Contract'但是''; 在名为'contract'的路由上下文操作参数中找不到任何值 - 您的匹配路由是否包含名为'contract'的令牌?

[SetUp]
public void Setup()
{
    MvcApplication.RegisterModelBinders();
    MvcApplication.RegisterRoutes(RouteTable.Routes);
}

[Test]
public void VersionEdit()
{
    var contract = TestHelper.CreateContract();
    var route = "~/Contract/" + contract.Id.ToString() + "/Version/Edit/" + 
        contract.Versions.Count;
    route.ShouldMapTo<VersionController>(c => c.Edit(contract));
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试调试自定义绑定器永远不会被调用.

我的路线定义:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "VersionToken", // Route name
                "Contract/{contractId}/Version/{version}/{action}/{token}", // URL with parameters
                new { controller = "Version", action = "ViewContract", version = 1, token = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "Version", // Route …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing asp.net-mvc-routing asp.net-mvc-3

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

使用iTextSharp验证PDF是否受到保护/保护

是否可以验证我们是否可以使用iTextSharp复制PDF文档的内容?

我有一个方法复制PDF的内容,并在最后添加一个新的页面与项目的信息,但它抛出"System.ArgumentException:PdfReader没有打开所有者密码".我这样做时会出现这个错误writer.GetImportedPage(reader, i);

谢谢您的帮助!

c# pdf itextsharp

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

Angular 2 index.html - 与开发和生产不同

我需要在我的angular 2项目中实现snipcart.下面的脚本标记需要插入到我的index.html文件的头部.

但是,data-api-key因开发和生产环境而异.我该怎么做?

<script src="https://cdn.snipcart.com/scripts/2.0/snipcart.js" 
        id="snipcart" 
        data-api-key="insert-your-key-here">
</script>
Run Code Online (Sandbox Code Playgroud)

java.html文件中的脚本标记很重要,snipcart.com会出于安全考虑进行检查.

我试图在运行时执行此操作:在index.html文件中添加不带src-url的脚本标记,然后在main.ts中使用正确的api-key值和src-url更新标记属性.

这样,snipcart会使用正确的密钥运行,但来自snipcart.com的验证失败.

所以我需要在编译时设置api-key.我的index.html在开发和生产模式上需要有所不同.

我的项目是使用angular cli创建的:

"angular-cli": "1.0.0-beta.19-3",

"@angular/common": "~2.1.0",
"@angular/compiler": "~2.1.0",
"@angular/core": "~2.1.0",
"@angular/forms": "~2.1.0",
"@angular/http": "~2.1.0",
"@angular/platform-browser": "~2.1.0",
"@angular/platform-browser-dynamic": "~2.1.0",
"@angular/router": "~3.1.0",
Run Code Online (Sandbox Code Playgroud)

谢谢,

干杯

格尔德

snipcart angular

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

.Contains()在EF Code First的2个属性上

是否可以在Where()中对两个不同的属性进行查询?例如,我想获取所有在FirstName和LastName属性中包含"Robert G"的用户.如果我做 :

var contacts = _session.All<Contact>()
    .Where(x => x.IsActive
                && (x.FirstName.ToLower().Contains(q.ToLower())
                    || x.LastName.ToLower().Contains(q.ToLower())));
Run Code Online (Sandbox Code Playgroud)

我将不会得到"Robert G"的结果,因为FirstName包含"Robert"和LastName"Gambonni".

我还考虑过制作一个新属性FullName,它只是一个Getter,但是我必须先加载它们,因为我的属性不在数据库中.

有什么建议?非常感谢!

c# linq entity-framework-4 ef-code-first

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