小编Ger*_*cke的帖子

使用Json数据和Knockout JS Viewmodel填充bootstrap选择

我在我的项目中使用JSON和bootstrap控件.在我的JSON中,我从我的数据中检索数据sql database.现在我想用我的数据填充我的选择控件,但它不起作用,我看不出我做错了什么,我搜索了很多小提琴让它工作.

这是我的JSON ::

    var Projectss = function (data) {
        var self = this;
        self.ProjectName = ko.observable(data.ProjectName);
    }

    var ProjectModel = function (Projects) {
        var self = this;
        self.Projects = ko.observableArray(Projects);

    $.ajax({
            url: "CreateTask.aspx/GetProjectList",
            // Current Page, Method  
            data: '{}',
            // parameter map as JSON  
            type: "POST",
            // data has to be POSTed  
            contentType: "application/json; charset=utf-8",
            // posting JSON content      
            dataType: "JSON",
            // type of data is JSON (must be upper case!)  
            timeout: 10000,
            // AJAX timeout  
            success: …
Run Code Online (Sandbox Code Playgroud)

json knockout.js

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

C#使用SHA1将字符串哈希到字节数组中

我正在使用SHA1来加密一些像密码这样的值.这是我的代码:

String passwd = Membership.GeneratePassword(10, 2);
SHA1 sha = new SHA1CryptoServiceProvider();
byte [] password = sha.ComputeHash(passwd);
Run Code Online (Sandbox Code Playgroud)

但VS返回错误,因为passwd是一个字符串.我必须将密码存储在字节数组中,那么有没有办法解决这个问题?

c# encryption sha1

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

何时"常量"类变量初始化

我有一个常量int变量定义为类变量:

我的课程定义如下:

public class ABC : XYZ
{
    private const int constantNumber = 600;

    public ABC(): base(constantNumber)
    {}

}
Run Code Online (Sandbox Code Playgroud)

它在调用基础构造函数时(即在调用它自己的构造函数之前)是否可用?

什么时候定义?

.net c#

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

实体框架已经有一个与此命令关联的开放DataReader,必须先关闭它

我正在努力解决上面的错误.我在这里发现了不同的答案(堆栈溢出),但它们都没有解决我与错误相关的问题.

我只是在我的ConnectionString中启用MARS但没有成功.

我有一类产品

public class Product
{
    public Product()
    {
        this.Additives = new HashSet<Additive>();
    }

    public int Id { get; set; }
    public string Name { get; set; } // refrigerante
    public string CommercialName { get; set; } // nome popular, ex: fanta laranja
    public string Brand { get; set; } // marca, ex: Coca-cola
    public string Details { get; set; } // composicao, ingredientes
    public HalalState HalalState { get; set; } // estado: halal, haram ou desconhecido
    public DateTime? …
Run Code Online (Sandbox Code Playgroud)

c# sql-server entity-framework lazy-loading eager-loading

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

从表行中的jquery模板获取下拉选择值

我有以下jquery模板,我想在单击按钮时从下拉框中获取所选值.

Jquery模板:

<script id="template-download" type="text/x-jquery-tmpl">
        <tr class="template-download{{if _errorMSG}} ui-state-error{{/if}}">
            {{if _errorMSG}}
                <td></td>
                <td class="name">${_name}</td>
                <td class="size">${sizef}</td>
                <td class="error" colspan="2">Error:
                    {{if _errorMSG === 1}}File exceeds upload_max_filesize
                    {{else _errorMSG === 2}}File exceeds MAX_FILE_SIZE (HTML form directive)
                    {{else _errorMSG === 3}}File was only partially uploaded
                    {{else _errorMSG === 4}}No File was uploaded
                    {{else _errorMSG === 5}}Missing a temporary folder
                    {{else _errorMSG === 6}}Failed to write file to disk
                    {{else _errorMSG === 7}}File upload stopped by extension
                    {{else _errorMSG === 'maxFileSize'}}File is too big …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

在ASP.NET MVC5中使用Ninject注入实体框架DbContext

我刚刚登陆依赖注入世界.

我有以下自定义DbContext-

public partial class SkyTrackerContext: DbContext
{
    public SkyTrackerContext(): base()
    {
        Database.SetInitializer(new SkyTrackerDBInitializer());
    }
}
Run Code Online (Sandbox Code Playgroud)

想在这个基础控制器中注入SkyTrackerContext-

public abstract class BaseController : Controller
{
    public BaseController() {}

    [Inject]
    public SkyTrackerContext MyDbContext { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

样品用法 -

public class LoginController : BaseController
{            
    public ActionResult ValidateLogin(Login login) 
    {
      var query = MyDbContext.Persons.Where(.....);
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该在NinjectWebCommon.cs中写什么来注入这个上下文?

private static IKernel CreateKernel()
{
    var kernel = new StandardKernel();
    try
    {
        kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

        RegisterServices(kernel);
        return kernel;
     }
     catch …
Run Code Online (Sandbox Code Playgroud)

entity-framework ninject asp.net-mvc-5

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

反序列化json对c#的响应

我无法反序列化以下响应:我的JSON是

json is
{
  "disclaimer": "Exchange rates/",
  "license": "Data sourced from various providers",
  "timestamp": 1435813262,
  "base": "USD",
  "rates": {
    "AED": 3.672973,
    "AFN": 60.150001,
    "ALL": 126.7792,
    "AMD": 472.46,
    "ANG": 1.78875,
    "AOA": 121.253666,
    "ARS": 9.095239,
    "AUD": 1.307011,
    "AWG": 1.793333,
    "AZN": 1.04955,
}
}
Run Code Online (Sandbox Code Playgroud)

控制器是:

[HttpPost]
public ActionResult Index(Test1 values)
{

    string appid = values.apikey;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://openexchangerates.org//api/latest.json?app_id=5db2fa81c8174a839756eb4d5a4a5e05");

    request.Method = "POST";

    using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream(), ASCIIEncoding.ASCII))
    {
        streamWriter.Write(appid1);
        streamWriter.Close();
    }

    string responseText = String.Empty;

    if (request.Headers.Count > 0)
    {

        using …
Run Code Online (Sandbox Code Playgroud)

c# json json-deserialization

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