Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CS1955非发票会员';Json';不能像方法一样使用_C#_Asp.net Mvc_Linqpad - Fatal编程技术网

C# CS1955非发票会员';Json';不能像方法一样使用

C# CS1955非发票会员';Json';不能像方法一样使用,c#,asp.net-mvc,linqpad,C#,Asp.net Mvc,Linqpad,如何在LinqPad中返回JsonResult,我遇到了一个问题。同样的代码在MVC应用程序中工作,但在LinqPad中不工作。我做错了什么 代码: 查看MVC内部(此代码在其中工作)Json方法定义如下: namespace System.Web.Mvc { public abstract class Controller : ControllerBase, IActionFilter, IAuthenticationFilter, IAuthorizationFilter, IDis

如何在LinqPad中返回
JsonResult
,我遇到了一个问题。同样的代码在MVC应用程序中工作,但在LinqPad中不工作。我做错了什么

代码:

查看MVC内部(此代码在其中工作)Json方法定义如下:

namespace System.Web.Mvc
{  
  public abstract class Controller : ControllerBase, IActionFilter, IAuthenticationFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter, IAsyncController, IController, IAsyncManagerContainer
  {      
    protected internal JsonResult Json(object data);
  }
}
在LinqPad中,我包含了MVC应用程序中包含的所有名称空间:

AjaxControlToolkit
AjaxControlToolkit.Bundling
AjaxControlToolkit.Design
AjaxControlToolkit.HtmlEditor
AjaxControlToolkit.HtmlEditor.Popups
AjaxControlToolkit.HtmlEditor.Sanitizer
AjaxControlToolkit.HtmlEditor.ToolbarButtons
AjaxControlToolkit.MaskedEditValidatorCompatibility
Antlr.Runtime
Antlr.Runtime.Debug
Antlr.Runtime.Misc
Antlr.Runtime.Tree
CKEditor.NET
com.itextpdf.text.pdf
com.itextpdf.text.pdf.languages
com.itextpdf.text.pdf.security
CommWeb
CommWeb1
CommWeb2
CommWeb3
EvoPdf
FakeHttpContext
FakeHttpContext.Switchers
fCatEve
fCatEve.Common
fCatEve.Controllers
fCatEve.Controls
fCatEve.fCommon
fCatEve.Helpers
fCatEve.Models
fCatEve.wf
fCatEve.wf.Controls
fDataReadWrite
fMedic.Controllers
FreeTextBoxControls
FreeTextBoxControls.Design
FreeTextBoxControls.Licensing
FreeTextBoxControls.Support
FreeTextBoxControls.Support.Sgml
GenCode128
iCommCommon
iPUURE
iPUURE.Controls
iPUURE.Data
iPUURE.IniFiles
iPUURE.Log
Ipuure.net
Ipuure.net.Controls
iPUURE.Net.Mail
iPUURE.Web
iPUURE.Web.iLocalization
iPUURE.Web.Localization
iPUURE.Web.UI
iPUURE.Web.UI.WebControls
iPUURE.Web.Utils
Itenso.TimePeriod
iTextSharp.awt.geom
iTextSharp.testutils
iTextSharp.text
iTextSharp.text.api
iTextSharp.text.error_messages
iTextSharp.text.exceptions
iTextSharp.text.factories
iTextSharp.text.html
iTextSharp.text.html.simpleparser
iTextSharp.text.io
iTextSharp.text.log
iTextSharp.text.pdf
iTextSharp.text.pdf.codec
iTextSharp.text.pdf.codec.wmf
iTextSharp.text.pdf.collection
iTextSharp.text.pdf.crypto
iTextSharp.text.pdf.draw
iTextSharp.text.pdf.events
iTextSharp.text.pdf.fonts.cmaps
iTextSharp.text.pdf.hyphenation
iTextSharp.text.pdf.interfaces
iTextSharp.text.pdf.intern
iTextSharp.text.pdf.languages
iTextSharp.text.pdf.parser
iTextSharp.text.pdf.qrcode
iTextSharp.text.pdf.security
iTextSharp.text.xml
iTextSharp.text.xml.simpleparser
iTextSharp.text.xml.simpleparser.handler
iTextSharp.text.xml.xmp
iTextSharp.xmp
iTextSharp.xmp.impl
iTextSharp.xmp.impl.xpath
iTextSharp.xmp.options
iTextSharp.xmp.properties
Microsoft.Ajax.Utilities
Microsoft.Build.Framework
Microsoft.Build.Framework.XamlTypes
Microsoft.Build.Tasks
Microsoft.Build.Tasks.Deployment.Bootstrapper
Microsoft.Build.Tasks.Deployment.ManifestUtilities
Microsoft.Build.Tasks.Hosting
Microsoft.Build.Tasks.Xaml
Microsoft.Build.Utilities
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Web.Infrastructure
Microsoft.Web.Infrastructure.DynamicModuleHelper
Microsoft.Web.Infrastructure.DynamicValidationHelper
MoreLinq
Newtonsoft.Json
Newtonsoft.Json.Bson
Newtonsoft.Json.Converters
Newtonsoft.Json.Linq
Newtonsoft.Json.Schema
Newtonsoft.Json.Serialization
OfficeOpenXml
OfficeOpenXml.ConditionalFormatting
OfficeOpenXml.ConditionalFormatting.Contracts
OfficeOpenXml.DataValidation
OfficeOpenXml.DataValidation.Contracts
OfficeOpenXml.DataValidation.Formulas.Contracts
OfficeOpenXml.Drawing
OfficeOpenXml.Drawing.Chart
OfficeOpenXml.Drawing.Vml
OfficeOpenXml.FormulaParsing
OfficeOpenXml.FormulaParsing.Excel
OfficeOpenXml.FormulaParsing.Excel.Functions
OfficeOpenXml.FormulaParsing.Excel.Functions.Database
OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime
OfficeOpenXml.FormulaParsing.Excel.Functions.Information
OfficeOpenXml.FormulaParsing.Excel.Functions.Logical
OfficeOpenXml.FormulaParsing.Excel.Functions.Math
OfficeOpenXml.FormulaParsing.Excel.Functions.Numeric
OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup
OfficeOpenXml.FormulaParsing.Excel.Functions.Text
OfficeOpenXml.FormulaParsing.Excel.Operators
OfficeOpenXml.FormulaParsing.ExcelUtilities
OfficeOpenXml.FormulaParsing.Exceptions
OfficeOpenXml.FormulaParsing.ExpressionGraph
OfficeOpenXml.FormulaParsing.ExpressionGraph.CompileStrategy
OfficeOpenXml.FormulaParsing.ExpressionGraph.FunctionCompilers
OfficeOpenXml.FormulaParsing.LexicalAnalysis
OfficeOpenXml.FormulaParsing.LexicalAnalysis.TokenSeparatorHandlers
OfficeOpenXml.FormulaParsing.Logging
OfficeOpenXml.FormulaParsing.Utilities
OfficeOpenXml.Packaging
OfficeOpenXml.Packaging.Ionic.Zip
OfficeOpenXml.Packaging.Ionic.Zlib
OfficeOpenXml.Style
OfficeOpenXml.Style.Dxf
OfficeOpenXml.Style.XmlAccess
OfficeOpenXml.Table
OfficeOpenXml.Table.PivotTable
OfficeOpenXml.Utils
OfficeOpenXml.VBA
Org.BouncyCastle.Apache.Bzip2
Org.BouncyCastle.Asn1
Org.BouncyCastle.Asn1.BC
Org.BouncyCastle.Asn1.Cmp
Org.BouncyCastle.Asn1.Cms
Org.BouncyCastle.Asn1.Cms.Ecc
Org.BouncyCastle.Asn1.Crmf
Org.BouncyCastle.Asn1.CryptoPro
Org.BouncyCastle.Asn1.Eac
Org.BouncyCastle.Asn1.Esf
Org.BouncyCastle.Asn1.Ess
Org.BouncyCastle.Asn1.Gnu
Org.BouncyCastle.Asn1.Iana
Org.BouncyCastle.Asn1.Icao
Org.BouncyCastle.Asn1.IsisMtt
Org.BouncyCastle.Asn1.IsisMtt.Ocsp
Org.BouncyCastle.Asn1.IsisMtt.X509
Org.BouncyCastle.Asn1.Kisa
Org.BouncyCastle.Asn1.Microsoft
Org.BouncyCastle.Asn1.Misc
Org.BouncyCastle.Asn1.Mozilla
Org.BouncyCastle.Asn1.Nist
Org.BouncyCastle.Asn1.Ntt
Org.BouncyCastle.Asn1.Ocsp
Org.BouncyCastle.Asn1.Oiw
Org.BouncyCastle.Asn1.Pkcs
Org.BouncyCastle.Asn1.Sec
Org.BouncyCastle.Asn1.Smime
Org.BouncyCastle.Asn1.TeleTrust
Org.BouncyCastle.Asn1.Tsp
Org.BouncyCastle.Asn1.Utilities
Org.BouncyCastle.Asn1.X500
Org.BouncyCastle.Asn1.X509
Org.BouncyCastle.Asn1.X509.Qualified
Org.BouncyCastle.Asn1.X509.SigI
Org.BouncyCastle.Asn1.X9
Org.BouncyCastle.Bcpg
Org.BouncyCastle.Bcpg.Attr
Org.BouncyCastle.Bcpg.OpenPgp
Org.BouncyCastle.Bcpg.Sig
Org.BouncyCastle.Cms
Org.BouncyCastle.Crypto
Org.BouncyCastle.Crypto.Agreement
Org.BouncyCastle.Crypto.Agreement.Kdf
Org.BouncyCastle.Crypto.Agreement.Srp
Org.BouncyCastle.Crypto.Digests
Org.BouncyCastle.Crypto.Encodings
Org.BouncyCastle.Crypto.Engines
Org.BouncyCastle.Crypto.Generators
Org.BouncyCastle.Crypto.IO
Org.BouncyCastle.Crypto.Macs
Org.BouncyCastle.Crypto.Modes
Org.BouncyCastle.Crypto.Modes.Gcm
Org.BouncyCastle.Crypto.Paddings
Org.BouncyCastle.Crypto.Parameters
Org.BouncyCastle.Crypto.Prng
Org.BouncyCastle.Crypto.Signers
Org.BouncyCastle.Crypto.Tls
Org.BouncyCastle.Math
Org.BouncyCastle.Math.EC
Org.BouncyCastle.Ocsp
Org.BouncyCastle.OpenSsl
Org.BouncyCastle.Pkcs
Org.BouncyCastle.Pkix
Org.BouncyCastle.Security
Org.BouncyCastle.Security.Certificates
Org.BouncyCastle.Tsp
Org.BouncyCastle.Utilities
Org.BouncyCastle.Utilities.Collections
Org.BouncyCastle.Utilities.Date
Org.BouncyCastle.Utilities.Encoders
Org.BouncyCastle.Utilities.IO
Org.BouncyCastle.Utilities.IO.Pem
Org.BouncyCastle.Utilities.Net
Org.BouncyCastle.Utilities.Zlib
Org.BouncyCastle.X509
Org.BouncyCastle.X509.Extension
Org.BouncyCastle.X509.Store
RazorEngine
RazorEngine.Compilation
RazorEngine.Compilation.CSharp
RazorEngine.Compilation.ImpromptuInterface
RazorEngine.Compilation.ImpromptuInterface.Build
RazorEngine.Compilation.ImpromptuInterface.Dynamic
RazorEngine.Compilation.ImpromptuInterface.InvokeExt
RazorEngine.Compilation.ImpromptuInterface.Optimization
RazorEngine.Compilation.Inspectors
RazorEngine.Compilation.ReferenceResolver
RazorEngine.Compilation.VisualBasic
RazorEngine.Configuration
RazorEngine.Configuration.Xml
RazorEngine.Templating
RazorEngine.Templating.Parallel
RazorEngine.Text
RestSharp
RestSharp.Authenticators
RestSharp.Authenticators.OAuth
RestSharp.Deserializers
RestSharp.Extensions
RestSharp.Extensions.MonoHttp
RestSharp.Serializers
RestSharp.Validation
System
System.Collections.Generic
System.ComponentModel.DataAnnotations
System.ComponentModel.DataAnnotations.Schema
System.ComponentModel.Design
System.ComponentModel.Design.Data
System.ComponentModel.Design.Serialization
System.Configuration
System.Configuration.Internal
System.Configuration.Provider
System.Data.Design
System.Data.Entity
System.Data.Entity.Core
System.Data.Entity.Core.Common
System.Data.Entity.Core.Common.CommandTrees
System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder
System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.Spatial
System.Data.Entity.Core.Common.EntitySql
System.Data.Entity.Core.EntityClient
System.Data.Entity.Core.Mapping
System.Data.Entity.Core.Metadata.Edm
System.Data.Entity.Core.Objects
System.Data.Entity.Core.Objects.DataClasses
System.Data.Entity.Infrastructure
System.Data.Entity.Infrastructure.Annotations
System.Data.Entity.Infrastructure.DependencyResolution
System.Data.Entity.Infrastructure.Design
System.Data.Entity.Infrastructure.Interception
System.Data.Entity.Infrastructure.MappingViews
System.Data.Entity.Infrastructure.Pluralization
System.Data.Entity.Migrations
System.Data.Entity.Migrations.Builders
System.Data.Entity.Migrations.Design
System.Data.Entity.Migrations.History
System.Data.Entity.Migrations.Infrastructure
System.Data.Entity.Migrations.Model
System.Data.Entity.Migrations.Sql
System.Data.Entity.Migrations.Utilities
System.Data.Entity.ModelConfiguration
System.Data.Entity.ModelConfiguration.Configuration
System.Data.Entity.ModelConfiguration.Conventions
System.Data.Entity.Spatial
System.Data.Entity.SqlServer
System.Data.Entity.SqlServer.Utilities
System.Data.Entity.Utilities
System.Data.Entity.Validation
System.Deployment.Internal.CodeSigning
System.Diagnostics.Design
System.Diagnostics.Tracing
System.DirectoryServices
System.DirectoryServices.ActiveDirectory
System.DirectoryServices.Protocols
System.EnterpriseServices
System.EnterpriseServices.CompensatingResourceManager
System.EnterpriseServices.Internal
System.Linq
System.Messaging.Design
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.Handlers
System.Net.Http.Headers
System.Resources
System.Resources.Tools
System.Runtime.Caching
System.Runtime.Caching.Configuration
System.Runtime.Caching.Hosting
System.Security.Cryptography
System.Security.Cryptography.Pkcs
System.Security.Cryptography.X509Certificates
System.Security.Cryptography.Xml
System.Security.Permissions
System.ServiceProcess
System.ServiceProcess.Design
System.Text
System.util
System.util.collections
System.util.zlib
System.Web
System.Web.Caching
System.Web.Compilation
System.Web.Configuration
System.Web.Configuration.Internal
System.Web.Globalization
System.Web.Handlers
System.Web.Helpers
System.Web.Hosting
System.Web.Http
System.Web.Http.Batch
System.Web.Http.Controllers
System.Web.Http.Dependencies
System.Web.Http.Description
System.Web.Http.Dispatcher
System.Web.Http.ExceptionHandling
System.Web.Http.Filters
System.Web.Http.Hosting
System.Web.Http.Metadata
System.Web.Http.Metadata.Providers
System.Web.Http.ModelBinding
System.Web.Http.ModelBinding.Binders
System.Web.Http.Results
System.Web.Http.Routing
System.Web.Http.Routing.Constraints
System.Web.Http.Services
System.Web.Http.Tracing
System.Web.Http.Validation
System.Web.Http.Validation.Providers
System.Web.Http.Validation.Validators
System.Web.Http.ValueProviders
System.Web.Http.ValueProviders.Providers
System.Web.Http.WebHost
System.Web.Instrumentation
System.Web.Mail
System.Web.Management
System.Web.ModelBinding
System.Web.Mvc
System.Web.Mvc.Ajax
System.Web.Mvc.Async
System.Web.Mvc.Extensions
System.Web.Mvc.Extensions.Html
System.Web.Mvc.Filters
System.Web.Mvc.Html
System.Web.Mvc.Razor
System.Web.Mvc.Routing
System.Web.Mvc.Routing.Constraints
System.Web.Optimization
System.Web.Profile
System.Web.Providers
System.Web.Providers.Entities
System.Web.Razor
System.Web.Razor.Editor
System.Web.Razor.Generator
System.Web.Razor.Parser
System.Web.Razor.Parser.SyntaxTree
System.Web.Razor.Text
System.Web.Razor.Tokenizer
System.Web.Razor.Tokenizer.Symbols
System.Web.RegularExpressions
System.Web.Routing
System.Web.Security
System.Web.Security.AntiXss
System.Web.Services
System.Web.Services.Configuration
System.Web.Services.Description
System.Web.Services.Discovery
System.Web.Services.Protocols
System.Web.SessionState
System.Web.UI
System.Web.UI.Adapters
System.Web.UI.Design
System.Web.UI.Design.Directives
System.Web.UI.Design.WebControls
System.Web.UI.Design.WebControls.WebParts
System.Web.UI.HtmlControls
System.Web.UI.WebControls
System.Web.UI.WebControls.Adapters
System.Web.UI.WebControls.WebParts
System.Web.Util
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Html
System.Web.WebPages.Instrumentation
System.Web.WebPages.Razor
System.Web.WebPages.Razor.Configuration
System.Web.WebPages.Scope
System.Web.WebSockets
System.Windows.Forms
System.Windows.Forms.ComponentModel.Com2Interop
System.Windows.Forms.Design
System.Windows.Forms.Design.Behavior
System.Windows.Forms.Layout
System.Windows.Forms.PropertyGridInternal
System.Windows.Forms.VisualStyles
TuesPechkin
TuesPechkin.EventHandlers
TuesPechkin.Util
WebGrease
WebGrease.Activities
WebGrease.Configuration
WebGrease.Css
WebGrease.Css.Ast
WebGrease.Css.Ast.Animation
WebGrease.Css.Ast.MediaQuery
WebGrease.Css.Ast.Selectors
WebGrease.Css.Extensions
WebGrease.Css.ImageAssemblyAnalysis
WebGrease.Css.ImageAssemblyAnalysis.LogModel
WebGrease.Css.Visitor
WebGrease.Extensions
WebGrease.ImageAssemble
WebGrease.Preprocessing

我发现解决方案控制器类必须实例化,并且这个方法应该在控制器内部,如下所示。谢谢Stephen Muecke

public class WorkOrderController : Controller
{
    public JsonResult test()
    {
        return Json(new { Result = "OK"});
    }
}

我觉得这样用比较好

return new JsonResult(searchResult);

因为MvcCore RazorPages中的多次类似使用ControllerBase是

您可能有另一个名为Json的类或属性。
Json
Controller
的一种方法。使用
returnnewjsonresult{Data=new{Result=“OK”}
return new JsonResult(searchResult);