小编Gar*_*rom的帖子

DELETE命令未访问WebAPI控制器

在通过ASP.NET Web API提交请求时,我很难在我的Controller上获取DELETE方法.它返回404,但我无法弄清楚原因.GET和POST请求按预期工作,返回项目列表以及提供id时的单个项目,但是当我使用DELETE请求调用API时,我得到404错误.

场景:

1. ASP.NET Web窗体应用程序......

虽然我已经安装了MVC4软件包以利用Web API功能,但它不是MVC应用程序.

2. global.asax中的路由表定义

            RouteTable.Routes.MapHttpRoute(

                    "Default", 
                    "api/{controller}/{id}", 
                    new { id = RouteParameter.Optional } 
            );
Run Code Online (Sandbox Code Playgroud)

3.控制器定义

    public HttpResponseMessage<Customer> Post(Customer customer)
    {
        CustomerDb.Customers.AddObject(customer);
        CustomerDb.SaveChanges();
        var response = new HttpResponseMessage<Customer>(customer, HttpStatusCode.Created);
        response.Headers.Location = new Uri(Request.RequestUri, "/api/Customer/"+customer.id.ToString());
        return response;
    }

    public CustomerDTO Get(int id)
    {
        CustomerDTO custDTO = null;
        Customer cust = CustomerDb.Customers.Where(c => c.id == id).SingleOrDefault();
        if (cust == null)
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        else
            custDTO = new CustomerDTO(cust);
        return custDTO;
    }

    public IEnumerable<CustomerDTO> Get()
    {
        IQueryable<Customer> …
Run Code Online (Sandbox Code Playgroud)

jquery httprequest asp.net-mvc-4 asp.net-web-api

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

类型定义存在于两个库中

我正在使用.NET 4.5构建ASP.NET Web Forms网站.

错误 ...

The type 'System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute' exists in both 'f:\Projects\web sites\RC1Iteration05\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
Run Code Online (Sandbox Code Playgroud)

我试图使用...来对库进行别名...

csc /r:EF_DataAnnotations="f:\Projects\web sites\RC1Iteration05\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll" /r:CM_DataAnnotations="c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll"
Run Code Online (Sandbox Code Playgroud)

但这只会导致"无源文件指定"同样令人困惑,因为源文件被指定为指示(此处此处).

我注意到该错误引用了net40文件夹中的EF dll而不是net45文件夹.我想如果我使用net45版本问题会自行解决,但我不知道如何更改该引用.我将"targetFramework"属性更改为packages.config文件中的EntityFramework包,但这没有任何区别.

我有点卡住,因为这两种解决方案似乎都没有做任何事情.

我环顾四周,在这里发现了一些帖子,人们处理了类似的问题,但没有收到回应.我希望有人可以提供帮助!

谢谢

G

c# asp.net webforms asp.net-4.5

16
推荐指数
2
解决办法
9660
查看次数

从短代码函数内部调用WordPress get_template_part首先渲染模板

我有一个页面,我需要允许用户输入一段文字.然后在该文本之后插入一个将呈现帖子列表的短代码,然后添加更多自由格式文本.我的想法是他们应该能够插入一个输出帖子的短代码.这样他们就可以简单地在他们希望帖子出现的地方添加短代码.

我目前有逻辑检索在自己的文件中分隔的帖子.目前我只需使用以下get_template_part()功能将其包含在页面中:

get_template_part('donation', 'posts');
Run Code Online (Sandbox Code Playgroud)

我研究了如何创建一个短代码,并在我的functions.php文件中包含以下代码以创建短代码:

add_shortcode('donation-posts', 'fnDonatePosts');   
function fnDonatePosts($attr, $content)
{
    get_template_part('donation', 'posts');    
}
Run Code Online (Sandbox Code Playgroud)

donation-posts.php该短码被放置的位置被正确执行和职位出现,但是,他们总是定位在内容之前不能及的.

我已经尝试删除该get_template_part()功能,只输出一些文本,并且工作正常.所以我明白这get_template_part()可能不是正确的方法,但是,我还没有找到办法去做我想做的事情(我确信有办法...我只是避风港'找到它).

我试过了:

include(get_template_directory(). '/donation-posts.php');
include_once(get_template_directory(). '/donation-posts.php') : 
Run Code Online (Sandbox Code Playgroud)

但是一旦他们点击了包含文件中的PHP代码,这些就停止了处理.

我也尝试过:

$file = file_get_contents(get_template_directory(). '/donation-posts.php');  
        return $file;
Run Code Online (Sandbox Code Playgroud)

但这只返回文件的内容(如函数名所示),这意味着它不会执行 PHP脚本来返回帖子.

以前有人这样做过吗?

php wordpress shortcode

9
推荐指数
2
解决办法
9542
查看次数

将ngModel绑定到自定义指令

所以我现在已经在这个问题上工作了一个星期,我似乎无法理解整个指令的事情.我看了很多帖子......

一堆视频......

并通过StackOverflow和其他论坛(链接跟随)希望有什么东西会沉入......我认为我遇到的问题是我想理解为什么/如何这些工作,以便我不会切割/粘贴某人别的解决方案进入我的代码,但后来不得不再问一些其他东西,因为我不知道我的粘贴代码在做什么.

然而,我发现每个人都有不同的方式来抚摸这只猫,但它们似乎都没有与我对这个应该如何工作的理解相符.

我试图做的是使用Metro UI CSS库构建表单.我想我会从一个简单的文本框开始.是的...只是一个简单的文本框.Metro UI文本框有一些很好的内置功能,我想保留,所以我认为这是一个很好的起点.

我读到为了利用AngularJS的Metro UI行为,我需要将它包装在自定义指令中(AngularJS ng-repeat中的自定义数据指令).虽然这个例子不正是我一直在寻找它似乎很容易解释什么,我需要做的.只需调用在指令的LINK函数中应用行为的函数,并将指令属性添加到input元素中......

所以我创建了一个名为'metroInputTransform'的指令,并将其作为属性添加到输入元素中.

<div data-ng-controller="pageOneFormCtrl as page">
    <input  type="text" id="txProductName" 
            data-ng-model="page.data.productName"
            data-metro-input-transform=""
            placeholder="product name" />
</div>
Run Code Online (Sandbox Code Playgroud)

在指令的LINK函数中,我简单地调用了应用我正在寻找的行为的方法.我知道这比它需要的更冗长,但我正在努力学习它,所以我尽我所能地踩过它....(完整代码见这个小提琴)

var metroDirectives = angular.module('metroDirectives', []);
    metroDirectives.directive('metroInputTransform', function ($compile) {

        function postLink($scope, element, attrs, controller) {

            $(element).inputTransform();
        };

        return {
            priority: 100,
            compile: function (element, attrs) {

                return { postLink };
            }
        };
    });
Run Code Online (Sandbox Code Playgroud)

所以这部分工作了.它创建了Metro外观和相关行为,但是...... ngModel没有绑定到该元素.因此,这开始了一个漫长的旅程,通过隔离范围,打破各种编译,控制器,预链接,后链接功能,至少两种不同的方式来持久化ngModel ......所有这些都无效.

经过各种阅读后,我的理解是DOM操作应该在COMPILE函数中进行,这样任何DOM转换都可用于编译,然后链接摘要过程的各个阶段.所以我将inputTransform()调用移动到COMPILE函数...( …

html javascript angularjs angularjs-directive angularjs-scope

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

基类方法可以返回派生类的类型吗?

基于我读过的其他帖子,似乎这可能是不可能的,但我想我会发布我想要做的事情,看看是否有人知道解决方案.

我正在尝试向Telerik Open Access域模型生成的类添加"Clone()"方法.没问题.我能够弄清楚如何将基类添加到生成的实体模型中,以便我可以通过它们的基类来识别这些类.(所有实体都从基类继承)

我希望所有这些实体模型类能够克隆自己.我也找到了解决方案.(深度克隆对象)

现在我有一个基类,我想在每个从该基类派生的类中添加一个Clone()函数.所以......似乎基类是放置它的自然场所......对吗?

public abstract class DBEntityBase
{
    /// <summary>
    ///     Gets a COPY of the instance in it's current state
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    protected T Clone<T>()
    {
        return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(this));
    }
}
Run Code Online (Sandbox Code Playgroud)

我添加了受保护的泛型Clone()方法,因为在基类级别我们不知道我们正在克隆的类型.Clone()方法需要由实体模型本身实现,以便提供克隆的特定类型.

public partial class DeliverableEntity
{
    public new DeliverableEntity Clone()
    {
        return this.Clone<DeliverableEntity>();
    }
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但不保证派生类将公开公开Clone()方法,因此我向基础添加了一个抽象Clone()方法,这将要求派生类实现公共Clone()方法.

public abstract class DarkRoomDBEntityBase
{
    /// <summary>
    ///     Gets a COPY of the …
Run Code Online (Sandbox Code Playgroud)

c# inheritance base-class

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

JQuery事件处理程序 - 什么是"最佳"方法

在JQuery中附加事件处理程序的以下方法之间有什么区别?

(function () {

    var $body = $("body");

    $('button').click(function () {
        console.log(this) + " - 1";
    });

    $('button').on('click', function () {
        console.log(this) + " - 2";
    });

    $(document).on('click', 'button', function () {
        console.log(this) + " - 3";
    });

    $body.on('click', 'button', function () {
        console.log(this) + " - 4";
    });

    $body.find('button').on('click', function () {
        console.log(this) + " - 5";
    });
})();
Run Code Online (Sandbox Code Playgroud)

我发现了一些似乎工作而另一个不工作的情况.例如处理程序2的下方,并工作一段时间的处理程序1一样.为了完成这项工作,我必须实现Handler 3,这显然效率较低.

$retrieveCust = $("#bxRetrieveCustomer");

// Handler 1
$retrieveCust.find(".icoX").on("click", function () { …
Run Code Online (Sandbox Code Playgroud)

jquery

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

寻找不存在的列

我收到消息......*无效的列名'PartLot_Id'*

我想这是指数据库中PART_LOT的ID字段.显然,这个表,没有其他人(不是很清楚,但相信我)拥有一个字段"PartLot_Id"所以表面上这是有道理的.

当我为这个表编写相应的实体时,我想让它更友好,所以我改变了表和字段的大小写,并在某些情况下完全重命名字段(试图区分业务问题和数据).然而,我确实用approriate属性修饰了类和属性,这些属性应该向EF发信号通知DataStore中的实际名称.到目前为止,这对我的所有实体都有效.

[Table("PART_LOT")]
public partial class PartLot : ModelBase
{
    [Key]
    [Column("ID")]
    public Int32 Id { get; set; }

    [Column("LOT_IDENT")]
    public String LotIdentity { get; set; }

    [Column("PART_ID")]
    public Guid? PartId { get; set; }

    [Column("COMPANYSITE_ID")]
    public Guid? CompanySiteId { get; set; }



    #region Navigation Properties

    [ForeignKey("PartId")]
    public virtual Part Part { get; set; }

    [ForeignKey("CompanySiteId")]
    public virtual Company Company { get; set; }

    public virtual ICollection<StrategicPart> StrategicParts { get; set; }

    public virtual ICollection<Product> Products{ get; set; } …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net entity-framework

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

清除我的 TEMP 文件夹后,SSDT 无法构建数据项目

在清除我的临时文件夹以释放一些急需的磁盘空间后,我在 Visual Studio 2012 中的 Sql Server Data Tools (SSDT) 不再构建我的数据项目,并且架构比较现在无用(因为它必须成功构建第一的)。我收到以下错误消息...

Error   187 04018: The "SqlBuildTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'C:\Users\gstenstrom\AppData\Local\Temp\b3546b57-815f-43e1-92a5-831cd4844026.9.tmp'.
Run Code Online (Sandbox Code Playgroud)

好的,所以问题很明显;我已经清楚地删除了我需要保留的东西。但是,我无法替换该文件,因为它已被永久删除,我该如何解决此问题?到目前为止,关于这方面的信息如此之少,令我感到震惊。任何帮助显然将不胜感激。

在这里寻找圣诞奇迹......快速而简单!!!:)

感谢您的帮助,祝您节日快乐!!

visual-studio-2012 sql-server-data-tools

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

在ASP.NET WebForms服务器端帖子之间坚持淘汰ViewModel ...

使用这篇文章发布在CodeProject.com上," 在ASP.NET应用程序中使用KnockoutJS "作为指南我试图使用ASP.NET 3.5 Web窗体创建一个可重用的,数据加载的下拉列表,但是它利用KnockoutJS作为客户端数据绑定.此下拉列表的多个独立实例应该能够在同一页面中独立存在.

到目前为止,CodeProject.com帖子在指导我如何进行设置方面非常有价值,并且我成功地将更新后的ViewModel数据作为JSON字符串在服务器和客户端之间来回传递,并将其转换为对象(以及从对象转换)在服务器和客户端上).我所依赖的是应该是简单的部分; 将ViewModel绑定到下拉列表!

所以我首先将JSON字符串加载到隐藏字段中.它包括一个区域列表和一个SelectedRegion.

<input type="hidden" id="ddlRegionKO_hdnRegionListVMStorage" value="{&quot;Regions&quot;:[{&quot;RegionName&quot;:&quot;Mid Atlantic USA&quot;,&quot;RegionId&quot;:2},{&quot;RegionName&quot;:&quot;Mid West USA&quot;,&quot;RegionId&quot;:10},{&quot;RegionName&quot;:&quot;North Central USA&quot;,&quot;RegionId&quot;:5},{&quot;RegionName&quot;:&quot;North East USA&quot;,&quot;RegionId&quot;:1},{&quot;RegionName&quot;:&quot;North West USA&quot;,&quot;RegionId&quot;:7},{&quot;RegionName&quot;:&quot;Other&quot;,&quot;RegionId&quot;:9},{&quot;RegionName&quot;:&quot;South Central USA&quot;,&quot;RegionId&quot;:6},{&quot;RegionName&quot;:&quot;South East USA&quot;,&quot;RegionId&quot;:3},{&quot;RegionName&quot;:&quot;South West USA&quot;,&quot;RegionId&quot;:8}],&quot;SelectedRegion&quot;:{&quot;RegionName&quot;:&quot;North Central USA&quot;,&quot;RegionId&quot;:5}}" />
Run Code Online (Sandbox Code Playgroud)

然后我使用该ko.utils.parseJson()函数将此字符串转换为Javascript对象.

var stringViewModel = document.getElementById("ddlRegionKO_hdnRegionListVMStorage").value;
var ddlRegionKO_pnlRegionDDLContainer_ViewModel = ko.utils.parseJson(stringViewModel);
Run Code Online (Sandbox Code Playgroud)

然后,我转换属性定义成ko.observableko.observableArray方法(这是将要进行重构的部分之一,但作为一个概念证明就足够了).

//
// Convert all the model properties to KO Propety/Methods
for (var propertyName in ddlRegionKO_pnlRegionDDLContainer_ViewModel) {
    switch(propertyName.toUpperCase())
    {
        //
        // Multiple Region objects are stored as an array in the regions property.
        case …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net webforms knockout.js

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

动态 Linq 谓词使用 C# MongoDB 驱动程序引发“不支持的过滤器”错误

我一直在尝试使用 Linq 将表达式的动态列表传递给 MongoDB C# 驱动程序查询......例如,此方法适用于针对 ORM 的常规 Linq 查询,但在应用于 MongoDB 查询时会导致错误...(仅供参考:我也在使用 LinqKit 的 PredicateBuilder)

//
// I create a List of Expressions which I can then add individual predicates to on an 
// "as-needed" basis.
    var filters = new List<Expression<Func<Session, Boolean>>>();

//
// If the Region DropDownList returns a value then add an expression to match it.
// (the WebFormsService is a home built service for extracting data from the various 
// WebForms Server Controls... in case you're wondering …
Run Code Online (Sandbox Code Playgroud)

c# linq mongodb mongo-c-driver mongodb-.net-driver

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