草庐IT

Level1Controller

全部标签

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# - 无法将带有 [] 的索引应用于 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# - 发现多个类型与名为 '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# - 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# - 为什么这个 web api Controller 不是并发的?

我有一个WebAPIController,其中包含以下方法:publicstringTester(){Thread.Sleep(2000);return"OK";}当我调用它10次(使用Fiddler)时,我预计所有10次调用都会在大约2秒后返回。然而,调用分别在2、4、8...20秒后返回。是什么阻止它同时运行?我该如何解决?常规Controller的行为是否与web-apiController相同? 最佳答案 您描述的内容与ASP.NETsession状态的默认行为相匹配,可以通过在web.config中禁用它来解决。Acces

c# - 从 Controller 到 View 的成功消息

目标我想在添加某些用户时在我的View中显示一些消息。问题当我们的模型出现问题时,有一个方法(ModelState.AddModelError)来处理不成功的消息。但是,当一切顺利时,我们如何处理向用户发送的消息,表明他的操作已成功?我找到了thisthread提供了一个解决方案,但大约三年过去了,我需要知道:没有另一种方法,也许更成熟?并不是说这不是,但我们仍然以同样的方式处理成功消息? 最佳答案 从BradChristie's展开answer,我创建了一个NuGet包,BootstrapNotifications,它将通过内置的

c# - 公开课 - "is inaccessible due to its protection level. Only public types can be processed."

我正在做一个测试项目来了解对象的XML序列化,但我遇到了一个奇怪的运行时错误:namespaceSerializeTest{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidserializeConnection(Connconnection){XmlSerializerserializer=newXmlSerializer(typeof(Conn));TextWritertextWrit

c# - 如何从 asp.net MVC 4 中的按钮单击调用 Controller

请问我在MVC网站上工作,我在索引页上有一个搜索页面和另一个搜索表单。当我从索引页面单击搜索按钮时,我想调用相同的搜索页面Controller。下面是我的按钮在索引页上的样子。'">SearchList是我在搜索页面中的搜索操作,Search是Controller名称。当我点击上面的按钮时,它以的形式返回urlhttp://localhost:52050/显示错误请求。我怀疑它来self的路由,我不确定如何实现它,请提供任何帮助。下面是我的路由routes.MapRoute(name:null,url:"Page{page}",defaults:new{Controller="Sear