草庐IT

listings_controller

全部标签

c# - 使用 ASP.NET Web API, Controller 如何返回使用 DotNetZip 库压缩的流图像集合?

我如何创建一个WebAPIController来生成并返回从内存中JPEG文件(MemoryStream对象)集合流式传输的压缩zip文件。我正在尝试使用DotNetZip库。我找到了这个例子:https://web.archive.org/web/20211020131216/https://www.4guysfromrolla.com/articles/092910-1.aspx#postadlink。但是Response.OutputStream在WebAPI中不可用,因此该技术不太有效。因此,我尝试将zip文件保存到新的MemoryStream;但它扔了。最后,我尝试使用Pus

c# - List<T>.Contains() 如何找到匹配项?

我有一个汽车对象列表Listcars=GetMyListOfCars();我想看看列表中是否有汽车if(cars.Contains(myCar)){}Contains使用什么来确定myCar是否在列表中。它是否对我的汽车对象执行“ToString()”。它是否使用Equals()方法,即gethashcode()?我知道我可以传递我自己的IEqualityComparer来强制我自己的实现,但只是想了解它默认情况下的作用。 最佳答案 直接来自MSDN-List.Contains:Thismethoddeterminesequalit

c# - 无法将带有 [] 的索引应用于 mvc Controller 中类型为“System.Collections.Generic.ICollection<int>”的表达式

publicActionResultaddstandardpackage1(ICollectionSingleStay,ICollectionDOUBLESTAY,ICollectionTRIBLESTAY,ICollectionFAMILYSTAY,ICollectionEXTRABED){vars=SingleStay;for(inti=0;i在for循环中,我收到类似无法将带[]的索引应用于类型表达式的错误,但我需要在for循环中,在我得到的每个中。因为基于for循环,我会将详细信息与其他集合列表绑定(bind)。请帮助我。我在varcal=Singlestay[i]中遇到错误。

c# - 将填充的 List<BaseClass> 转换为 List<ChildClass>

我有一个List里面有成员。我想将列表(及其所有成员)转换为类型List,其中ChildClass继承BaseClass.我知道我可以通过foreach获得相同的结果:ListChildClassList=newList();foreach(variteminBaseClassList){ChildClassList.Add(itemasChildClass);}但是有没有更简洁的方法呢?注意-这是在WP7平台上完成的。 最佳答案 如果你真的确定所有元素都是可类型转换的,你可以这样做:ChildClassList=BaseClass

c# - 发现多个类型与名为 'Home' 的 Controller 匹配 - 在两个不同的区域

我的项目有两个区域。现在,当我运行该程序时,出现此错误:Multipletypeswerefoundthatmatchthecontrollernamed'Home'.Thiscanhappeniftheroutethatservicesthisrequest('{controller}/{action}/{id}')doesnotspecifynamespacestosearchforacontrollerthatmatchestherequest.Ifthisisthecase,registerthisroutebycallinganoverloadofthe'MapRoute'm

c# - 从 ASP MVC 中的区域 Controller 链接到根 Controller

如何从我的区域之一链接到我的根Controller之一?这给了我一个错误:Norouteintheroutetablematchesthesuppliedvalues.我的根Controller集合中名为Admin的文件夹中有一个名为Page的Controller。我可以通过键入\Admin\Page访问此Controller。这是我注册路线的方式:routes.MapRoute("Admin","Admin/{controller}/{action}/{id}",new{controller="Admin",action="Index",id=""});我希望我可以使用我认为的这种语

c# - 如何将 DataSource 转换为 List<T>?

我有以下在DataGridView上加载产品的方法privatevoidLoadProducts(Listproducts){Source.DataSource=products;//SourceisBindingSourceProductsDataGrid.DataSource=Source;}现在我正试图将它们还给我以保存它们,如下所示。privatevoidSaveAll(){Repositoryrepository=Repository.Instance;Listproducts=(List)Source.DataSource;Console.WriteLine("Estees

c# - Autofac - 确保 Controller 有一个无参数的公共(public)构造函数

我知道之前有人问过这个问题并回答过-我问这个问题的原因是(我认为)我尝试了所有建议的解决方案来解决这个问题,但仍然无法解决。我有一个ASP.NETWebAPI2.0项目。我安装了Autofac、Autofac.Mvc5和Autofac.WebApi2依赖项。当我尝试调用APIController时,出现以下错误:Anerroroccurredwhentryingtocreateacontrolleroftype'MyController'.Makesurethatthecontrollerhasaparameterlesspublicconstructor.在我的Global.asax

c# - 可以将私有(private)方法放在我的 Controller 中,还是应该使用 asp.net mvc 将它们分离到某种类型的帮助程序类中?

我有一个Controller,可以根据用户类型加载一些下拉菜单。例如:publicActionResultIndex(){switch(SessionHelper.ViewLimit){case"C":ViewData["CustDivision"]=LoadCustDivisions();ViewData["Customer"]=LoadCustomers();break;case"P":ViewData["Customer"]=LoadCustomers();ViewData["Employee"]=LoadEmployees();break;case"D":ViewData["C

c# - 如何并行启动 List<Task>?

我有一个返回System.Threading.Tasks.Task的对象:publicclassMyClass{publicTaskGetTask(objectstate,CancellationTokencancellationToken){returnnewTask(Execute,state,cancellationToken);}publicvoidExecute(objectcontext){//dostuff}}在其他地方我有一个List,所以我执行以下操作以获得List:varmyTaskList=myClassList.Select(p=>p.GetTask(null,