草庐IT

func_i_dont_control

全部标签

c# - ASP .NET MVC - 有一个在响应中返回图像的 Controller 方法吗?

如何创建一个名为GetMyImage()的Controller方法,它返回一个图像作为响应(即图像本身的内容)?我考虑过将返回类型从ActionResult更改为string,但这似乎没有按预期工作。 最佳答案 返回FilePathResult使用FileController方法publicActionResultGetMyImage(stringImageID){//ConstructabsoluteimagepathvarimagePath="whatever";returnbase.File(imagePath,"image/

c# - 将 Func<T> 转换为 Func<object>

我想知道如何通过Func至Func方法参数:publicvoidFoo(Funcp)whereT:class{Foo(p);}publicvoidFoo(Funcp){}奇怪的是,它在NET4.0类库中有效,但在Silverlight4类库中无效。实际上我希望它在Silverlight中工作,并且我有像Func这样的输入参数 最佳答案 这样就可以了:publicvoidFoo(Funcp)whereT:class{Funcf=()=>p();Foo(f);} 关于c#-将Func转换为F

c# - Entity Framework 过滤器 "Expression<Func<T, bool>>"

我正在尝试为EntityFramework列表创建一个过滤方法并更好地理解Expression我有一个这样的测试函数。publicIQueryableFilter(IEnumerablesrc,Expression>pred){returnsrc.AsQueryable().Where(pred);}如果我这样做:context.Table.Filter(e=>e.ID或者这个:context.Table.Filter(e=>e.SubTable.Where(et=>et.ID0&&e.ID一切正常。但是如果我这样做:context.Table.Filter(e=>e.SubTable

c# - 如何更改 URL 中的 ASP.NET MVC Controller 名称?

如果我们有"example_name",我们可以使用[ActionName("")]在url中更改它所以,我想为Controller名称执行此操作。我能做到:ControllerName>example_nameController>在URL中:"/example_controller"我想在URL中像这样更改Controller名称:"/example-conroller" 最佳答案 您需要使用AttributeRouting,MVC5中引入的功能。根据您的示例,您应该按如下方式编辑您的Controller:[RoutePrefi

c# - 在 MVC4 中添加 Controller 不起作用

我使用的是VS2010Premium。我有一个使用SqlCe4.0和EntityFramework模型的MVC4项目。模型是:publicclassProjectBuild{publicintProjectBuildID{get;set;}publicstringname{get;set;}}publicclassProjectBuildContext:DbContext{publicDbSetbuilds{get;set;}}下面是我的连接字符串:addname="ProjectBuildContext"connectionString="DataSource=|DataDirect

c# - 无法使用 Entity Framework 创建 Controller - 无法检索元数据

我正在使用VS2013当我尝试创建一个“MVC5ControllerwithviewsusingentityFramework”时,我收到以下错误:therewasanerrorrunningtheselectedcodegenerator''UnabletoretrievemetadataforWebApplication.Domain.Entities.Product'.'EFDbContext.csusingSystem.Data.Entity;usingWebApplication.Domain.Entities;namespaceWebApplication.Domain.C

c# - 对传递 Expression 与 Func 参数感到困惑

我在理解表达式和函数的工作方式之间的区别时遇到了一些困难。当有人更改方法签名时出现此问题:publicstaticListThingList(FuncaWhere)到publicstaticListThingList(Expression>aWhere)这破坏了我的调用代码。旧的调用代码(有效)如下所示:...objecty=newobject();FuncwhereFunc=(p)=>p==y;things=ThingManager.ThingList(whereFunc);新代码(不起作用)如下所示:...objectx=newobject();Expression>whereEx

c# - Action 和 Func 参数不明确

这段代码怎么可能TaskManager.RunSynchronously(fileMananager.BackupItems,package);导致编译错误Thecallisambiguousbetweenthefollowingmethodsorproperties:'TaskManager.RunSynchronously(System.Action,MyObject)'and'TaskManager.RunSynchronously(System.Func,MyObject)'当Action的签名是publicvoidBackupItems(MyObjectpackage)和“模

c# - 从 MVC Controller 返回带有对象列表的 JsonResult

我的MVCController中有一个简单的方法:[HttpPost]publicJsonResultGetAreasForCompany(intcompanyId){varareas=context.Areas.Where(x=>x.Company.CompanyId==companyId).ToList();returnJson(areas);}这是一个区域对象:publicclassArea{publicintAreaId{get;set;}[Required]publicstringTitle{get;set;}publicboolArchive{get;set;}public

c# - 如何将 LambdaExpression 转换为类型化的 Expression<Func<T, T>>

我正在为nHibernate动态构建linq查询。由于依赖关系,我想稍后再转换/检索类型化的表达式,但到目前为止我一直没有成功。这是行不通的(强制转换应该发生在其他地方):varfuncType=typeof(Func).MakeGenericType(entityType,typeof(bool));vartypedExpression=(Func)Expression.Lambda(funcType,itemPredicate,parameter);//Fails这是有效的:vartypedExpression=Expression.Lambda>(itemPredicate,pa