小编Sha*_*eKm的帖子

ControllerDescriptor FindAction返回null

控制器:

[HttpDelete]
public ActionResult Delete(int id)
{
}
Run Code Online (Sandbox Code Playgroud)

方法:

ControllerBase controllerToLinkTo = string.IsNullOrEmpty(controllerName)
                                        ? htmlHelper.ViewContext.Controller
                                        : GetControllerByName(htmlHelper, controllerName);

var controllerContext = new ControllerContext(htmlHelper.ViewContext.RequestContext, controllerToLinkTo);
var controllerDescriptor = new ReflectedControllerDescriptor(controllerToLinkTo.GetType());
ActionDescriptor actionDescriptor = controllerDescriptor.FindAction(controllerContext, actionName);
Run Code Online (Sandbox Code Playgroud)

当操作具有[Delete]属性时,ActionDescriptor为null.有没有办法从控制器上下文获取操作名称?

c# asp.net-mvc asp.net-mvc-4

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

LINQ区分大小写

如何根据情况使LINQ区分大小写并且不区分大小写?

我正在使用sql server 2008和Entity Framework 4.0.

我更改了COLLATION以使SQL Server区分大小写.所以对于这样的场景:

 query = query.Where(x => x.Username == username);
Run Code Online (Sandbox Code Playgroud)

它很棒.但是,当按主题(或名称或类似)搜索时,我需要能够从db 忽略大小写中提取数据,如下所示:

query = query.Where(x => (x.Name.Contains(Name)));
Run Code Online (Sandbox Code Playgroud)

当记录是"TestString"并且我正在寻找"测试"或"测试"或类似时,它不起作用.我如何才能使它在文本中找到文本或字符串的一部分?谢谢

sql linq linq-to-entities

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

什么是.net应用程序的生命周期

有一个简单的.net .exe应用程序.一旦执行它的生命周期是什么.我的理解是发生以下情况:

> 1. OS loads exe assemblies into memory
> 2. OS checks if it is in fact .net assembly
> 3. mscoree.dll loads, and loads CLR
> 4. CLR takes over and loads external dlls, GC stuff, memory management etc.
> 5. CLR creates app domain where exe assemblies are loaded
> 6. exe is started
Run Code Online (Sandbox Code Playgroud)

鉴于以上是正确的(请随意详细说明),我对CLR加载程序集时的最后一步感兴趣.

  1. 创建了多少堆栈,堆,线程?是否创建了线程并执行可执行文件中的代码?
  2. 分配的初始内存大小是多少?谁分配内存(OS或CLR?)
  3. 它如何知道最初需要多少内存?
  4. 如果exe运行时需要更多内存,谁决定分配这个内存多少以及何时分配?
  5. 关闭exe时会发生什么?CLR在卸载App Domain之前是否运行任何GC?(关闭exe),还是操作系统?

.net c#

7
推荐指数
2
解决办法
1587
查看次数

使用moq模拟IEnumerable <T>

有了这个界面,我怎么能用moq模拟这个对象?

public interface IMyCollection : IEnumerable<IMyObject>
{
    int Count { get; }
    IMyObject this[int index] { get; }
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

无法将表达式IEnumerable转换为IMyCollection

c# asp.net unit-testing moq

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

Jquery或Javascript检查对象是否存在于Json对象的集合中

给出像这样的json字符串:

[{"id":28,"Title":"Sweden"},{"id":56,"Title":"USA"},{"id":89,"Title":"England"}]
Run Code Online (Sandbox Code Playgroud)

我需要检查一个对象是否存在,检查所有字段,意思是:

{"id":28,"Title":"Sweden"} => exists
{"id":29,"Title":"Sweden"} => doesn't exist
Run Code Online (Sandbox Code Playgroud)

要么

{"id":28,"Title":"Sweden"} => exists
{"id":28,"Title":"Sweden2"} => doesn't exist
Run Code Online (Sandbox Code Playgroud)

集合可以包含任意数量的对象,对象将始终具有相同数量的属性(id,title)或(id,title,firstName)等.

另外,为了检查现有对象,是否需要将字符串解析为json对象集合?

我试过这个:

$.map(val, function (obj) {
    if (obj === val)
        alert('in');
    return obj; // or return obj.name, whatever.
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-plugins

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

使用Docker运行TFS

我一直在阅读很多关于Docker及其用途的内容.目前,我们正在使用TFS构建和部署我们的内部应用程序(.net c#).过渡到Docker有什么好处吗?设置的意义是在TFS运行构建之后,它将部署到容器中吗?

目前除了做一堆手动步骤之外,没有简单的方法来运行构建:如何:在桌面上构建团队项目.

  • 你能在Windows Server上运行docker吗?
  • 我们能够使用docker设置我们的VM,以便我们可以在本地(到我们的vms)部署/模仿部署过程吗?
  • 并为我们的生产环境设置相同的流程?

tfs build-server docker boot2docker

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

JQuery发现最接近兄弟div

对于以下内容:

                    <div class="section">
                        <div class="row infoOn">
                            <div class="itemWrap clearfix">
                                <div class="itemTop clearfix">
                                </div>
                                <label class="">File title:</label>
                                <div class="inputWrap clearfix">
                                    <input type="text" class="text inpButton" value="upload file first" disabled="true"/>
                                    <a id="fileUpload" href="#" class="button">Browse</a>
                                </div>
                            </div>
                        </div>

                        <!-- filelist -->
                        <div class="row uploadList">
                            <div class="itemWrap clearfix">
                                <label>&nbsp;</label>
                                <div class="inputWrap clearfix" style="position:relative;">
                                    <ul>
                                        <li><span class="qq-upload-file">companyPic.png</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">companyPic.png</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">untitled.bmp</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">This i...Document.docx</span><span class="qq-upload-spinner"></span><span …
Run Code Online (Sandbox Code Playgroud)

jquery

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

Jquery克隆并重命名输入字段

我有以下内容:

<!-- group clone //-->
<div class="section">
    <div class="parent row infoOn">
        <div class="validGroup">
            <a title="remove" class="iconClose" href="#">remove</a>
                <div class="grouping">
                    <div class="clearfix valid">
                        <label>Name<span class="iconReq">&nbsp;</span>:</label>
                        <input type="password" class="text inpButton" name="items[0].first">
                    </div>
                    <div class="clearfix">
                        <label>Email<span class="iconReq">&nbsp;</span>:</label>
                        <input type="text" class="text inpButton" name="items[0].first">
                    </div>
                </div>
            </div>
        </div>
        <div class="row addControl">
            <a href="#" class="button">Add</a>
        </div>
    </div>
    <!-- group clone //-->
Run Code Online (Sandbox Code Playgroud)

和jQuery:

$(function(){
    // Control clone
    $('div.addControl a.button').click(function (e){
        e.preventDefault();
        var parent = $(this).closest('.section').find('.parent:last');
        var parentInput = parent.clone();
        parentInput.find("input").val("");
        parent.after(parentInput);
    });
    $('div.validGroup a.iconClose').live('click', function (e){
        e.preventDefault(); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery javascript-events

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

Querystring - 在c#中为querystring添加值

如何为查询字符串添加值?

我正在尝试这样做:

String currurl = HttpContext.Current.Request.RawUrl;
var querystring = HttpContext.Current.Request.QueryString.ToString();

var PrintURL = currurl + (String.IsNullOrEmpty(querystring)) ?
    HttpContext.Current.Request.QueryString.Add("print", "y") : string.Empty;
Run Code Online (Sandbox Code Playgroud)

但我一直收到这个错误:

无法将类型'string'隐式转换为'bool'

我要做的就是获取当前网址并将"pring = y"添加到查询字符串

.net c# asp.net

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

带有实例参数的SQL连接字符串

我正在尝试检查(在.net c#中)我是否能够连接到SQL服务器.但是每当我在连接字符串中指定实例时,我就无法再连接了.:

这有效:

builder.ConnectionString = "Server=DLS-534;user id=sa;password=Mypassword;initial catalog=master";
Run Code Online (Sandbox Code Playgroud)

这不起作用:

builder.ConnectionString = "Server=DLS-534\\SQL_2008_R2_DEV;user id=sa;password=Mypassword;initial catalog=master";
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?我确实需要能够连接到特定的实例,因为用户可能有几个dbs.

我的完整代码:

            SqlConnectionStringBuilder builder =
                new SqlConnectionStringBuilder();

builder.ConnectionString = "Server=DLS-534\\SQL_2008_R2_DEV;user id=sa;password=Mypassword;initial catalog=master";

            using (var connection = new SqlConnection(builder.ConnectionString))
            {
                try
                {
                    connection.Open();
                    return true;
                }
                catch (SqlException)
                {
                    return false;
                }
            }
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server asp.net c#-4.0

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