问题:我正在使用MVC4 WebAPI并在Get()调用期间抛出错误.
错误:
System.ArgumentException:类型'Comments2.Controllers.CommentsController'没有默认构造函数
堆栈跟踪:
at System.Linq.Expressions.Expression.New(Type type)
at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"}
Run Code Online (Sandbox Code Playgroud)
我很乐意提供任何代码,只需告诉我你想看到的内容.
控制器:
namespace Comments2.Controllers
{
//[Authorize]
public class CommentsController : ApiController
{
ICommentRepository repository;
public CommentsController(ICommentRepository repository)
{
this.repository = repository;
}
[Queryable]
public IQueryable<Comment> GetComments()
{
return repository.Get().AsQueryable();
}
public Comment GetComment(int id)
{
Comment comment;
if (!repository.TryGet(id, out comment))
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
return comment;
}
}
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$(function() {
$("#getComments").click(function () {
// We're using a Knockout model. This …Run Code Online (Sandbox Code Playgroud) 我有一个从 .aspx.cs 页面调用的存储过程。我有一个参数,在调用 sproc 时有时无法发送。因此,我正在执行以下操作:
IF @variable is null
BEGIN
...do this...
END
Else
...do that...
Run Code Online (Sandbox Code Playgroud)
我的问题出在 IF 语句中。据我所知,当我使用以下任何一项时:
if @parameterVariable = nullif @parameterVariable = ''if @parameterVariable <= 0没发生什么事!?当我在 SSMS 中调试 sproc 时,我发现(即使参数为空(没有用户选择))光标会转到并运行 ELSE 语句中的代码。难道我做错了什么?
谢谢!
什么是以下代码的"非控制台应用程序"表示.
class Sword
{
public void Hit(string target)
{
Console.WriteLine("Chopped {0} clean in half", target);
}
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚这个代码在C#ASP.NET MVC项目中会是什么样子.
我在Excel电子表格中循环访问数据时遇到问题.
对于A列中的每个值,搜索B列中所有值中的值.如果True插入"重复"
到目前为止,我尝试了多种变体: =IF(A2=$B$2:$B$14,"duplicate",)
我试着VLOOKUP和MATCH并INDEX用MATCH,但还没有到已经能够想出解决办法.
我相信一个vba脚本会更有效但似乎无法弄明白,你能帮忙吗?