小编Cal*_*ass的帖子

使用KnockoutJS的TypeScript

是否有任何使用TypeScript和KnockoutJS的示例?我只是好奇他们将如何一起工作?

编辑

这就是我所拥有的,似乎有效

declare var ko: any;
declare var $: any;
class ViewModel {
    x = ko.observable(10);
    y = ko.observable(10);

}

$(() => {
    ko.applyBindings(new ViewModel());
});
Run Code Online (Sandbox Code Playgroud)

这会生成以下Javascript:

var ViewModel = (function () {
    function ViewModel() {
        this.x = ko.observable(10);
        this.y = ko.observable(10);
    }
    return ViewModel;
})();
$(function () {
    ko.applyBindings(new ViewModel());
});
Run Code Online (Sandbox Code Playgroud)

knockout.js typescript

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

在ASP.NET Web API中处理ModelState验证

我想知道如何使用ASP.NET Web API实现模型验证.我的模型是这样的:

public class Enquiry
{
    [Key]
    public int EnquiryId { get; set; }
    [Required]
    public DateTime EnquiryDate { get; set; }
    [Required]
    public string CustomerAccountNumber { get; set; }
    [Required]
    public string ContactName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

然后我在我的API控制器中有一个Post动作:

public void Post(Enquiry enquiry)
{
    enquiry.EnquiryDate = DateTime.Now;
    context.DaybookEnquiries.Add(enquiry);
    context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

如何添加if(ModelState.IsValid)然后处理错误消息以传递给用户?

c# asp.net-web-api

100
推荐指数
6
解决办法
10万
查看次数

查看项目是否在数据库列中出现多次

我想检查一块数据是否在使用SQL的表中的特定列中出现多次.这是我到目前为止的SQL代码:

select * from AXDelNotesNoTracking where count(salesid) > 1
Run Code Online (Sandbox Code Playgroud)

salesid 是我希望检查的专栏,任何帮助将不胜感激,谢谢.

sql

53
推荐指数
2
解决办法
13万
查看次数

Angular Bootstrap模态:未知提供者:$ modalInstanceProvider

我正在尝试使用Angular Bootstrap Modal指令(http://angular-ui.github.io/bootstrap/),如下所示,在我的控制器中打开模态:

function customerSearch() {
    var modalInstance = $modal.open({
        templateUrl: 'app/customer/customers.modal.html',
        controller: 'customers.modal'
    });

    modalInstance.result.then(function(selectedCustomer) {
        console.log(selectedCustomer);
    });
}
Run Code Online (Sandbox Code Playgroud)

在模态控制器中:

var controllerId = 'customers.modal';

angular.module('app').controller(controllerId,
    ['$modalInstance', customersModal]);

function customersModal($modalInstance) {
    // Modal controller stuff
}
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到以下错误:

Unknown provider: $modalInstanceProvider <- $modalInstance
Run Code Online (Sandbox Code Playgroud)

如果我拿出来$modalInstance,它可以工作,但我显然没有参考调用控制器中的模态..

编辑

我不知道是否值得注意,但我使用Controller As语法:

<div class="container-fluid" data-ng-controller="customers.modal as vm">
Run Code Online (Sandbox Code Playgroud)

应用依赖:

var app = angular.module('app', [
    // Angular modules 
    'ngAnimate',        // animations
    'ngRoute',          // routing
    'ngSanitize',       // sanitizes html bindings (ex: sidebar.js)

    // Custom modules …
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap angularjs

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

数组必须包含1个元素

我有以下课程:

public class CreateJob
{
    [Required]
    public int JobTypeId { get; set; }
    public string RequestedBy { get; set; }
    public JobTask[] TaskDescriptions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想在上面有一个数据注释,TaskDescriptions以便数组必须包含至少一个元素?非常喜欢[Required].这可能吗?

.net c# asp.net-mvc model-validation asp.net-mvc-3

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

Go:找不到包"fmt"错误

我想Hello, World在go中关注一个简​​单的应用程序:

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello World!")
}
Run Code Online (Sandbox Code Playgroud)

但是当我构建并运行它时,我收到以下错误:

main.go:5:2: cannot find package "fmt" in any of:
    /home/user/go/src/pkg/fmt (from $GOROOT)
    /home/user/gocode/src/fmt (from $GOPATH)
package test_program
    imports runtime: cannot find package "runtime" in any of:
    /home/user/go/src/pkg/runtime (from $GOROOT)
    /home/user/gocode/src/runtime (from $GOPATH)
Run Code Online (Sandbox Code Playgroud)

这是输出go env:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/gocode"
GORACE=""
GOROOT="/home/user/go"
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
Run Code Online (Sandbox Code Playgroud)

go

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

在创建模型时不能使用上下文

在我的应用程序中,我收到以下错误:

在创建模型时不能使用上下文.

我不确定这意味着什么.我做了一切正常,通常它的工作原理,但对于这一个,它不是.以下是我的代码:

App.config中:

 <connectionStrings>
    <add name="DatabaseContext" connectionString="Data Source=./SQLEXPRESS;Initial Catalog=ProjectCode;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
 </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

Products.cs:

class Products
{
    public int ProductID { get; set; }
    public string ProductName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

DatabaseContext.cs:

class DatabaseContext : DbContext
{
    public DbSet<Products> Products { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Program.cs中:

DatabaseContext context = new DatabaseContext();

try
{
   var products = context.Products.ToList();

   foreach (var item in products)
   {
      Console.WriteLine(item.ProductID + " : " + item.ProductName);
   }
      Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

这条线是失败的 var products = context.Products.ToList(); …

c# entity-framework

25
推荐指数
3
解决办法
7万
查看次数

可以重定向到新页面的Ajax.BeginForm

我的@Ajax.BeginForm模型有一个布尔值(@Html.CheckBoxFor).如果选中此选项,我希望我的HttpPost操作重定向到新页面.否则我希望它继续作为@Ajax.BeginForm并更新页面的一部分.

这是我的HttpPost动作(注意:Checkout是我模型中的布尔值)

控制器:

    [HttpPost]
    public ActionResult UpdateModel(BasketModel model)
    {
        if (model.Checkout)
        {
            // I want it to redirect to a new page
            return RedirectToAction("Checkout");
        }
        else
        {
            return PartialView("_Updated");
        }
    }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-3

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

模型验证/ ASP.NET MVC 3 - 条件必需属性

我的ASP.NET MVC 3应用程序遇到了问题.我在我的模型中有2个属性,我只想在我的视图中根据其中任何一个为空而需要其中一个属性.例如,如果我输入电话号码,则不再需要电子邮件,反之亦然,但如果我将两者都留空,则应该需要1,下面是我的模型:

[Display(Name = "Contact Phone Number:")]
[MaxLength(150)]
public string ContactPhoneNumber { get; set; }

[Display(Name = "Contact Email Address:")]
[MaxLength(100)]
public string ContactEmailAddress { get; set; }
Run Code Online (Sandbox Code Playgroud)

我是否需要创建自定义属性来验证我的模型,如果是,我将如何实现这一目标?

model-validation asp.net-mvc-3

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

实现$ scope的延迟.$ watch

我想知道是否有可能在$ scope上实施一点延迟.$ watch.我有以下查询服务器,所以我想在评估query服务器之前稍微延迟.我注意到如果你快速键入它会混淆并且不会发送正确的信息:

$scope.$watch("query", function () {
    $scope.loading = true;
    returnFactory.query($scope.query).then(function (returns) {
        $scope.returns = returns;
        $scope.loading = false;
    });
});
Run Code Online (Sandbox Code Playgroud)

angularjs

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