草庐IT

core-ajax

全部标签

c# - JQuery ajax 调用在 200 上执行错误

这个问题在这里已经有了答案:Ajaxrequestreturns200OK,butanerroreventisfiredinsteadofsuccess(14个答案)关闭7年前。我的c#/WebApi服务器代码如下所示:[HttpPost]publicHttpResponseMessageLogout(){//dosomestuffhere...returnRequest.CreateResponse(HttpStatusCode.OK);}在客户端中,我使用jquery2.0.3执行ajax调用添加:Jquery代码(typescript)...varajaxSettings:JQu

c# - 在没有 @HTML.Beginform 的情况下发布表单并在 asp.net MVC 中使用 Jquery(ajax)

如何在不使用@HTML.Beginform而改用JQueryAjax的情况下填写表单?现在我尝试了:varpostData={form1:username,form2:password};$.ajax({type:"POST",url:'/Controller/Method',data:postData,dataType:"json",traditional:true});但是在发布之后,浏览器没有导航到正确的View。当然,我在Controller中正确地返回了View()。使用Fiddler我看到它已正确发布并且响应也正确......我必须使用@HTML.Beginform还是可以

c# - 如何在 EF Core 中查询多对多关系

我正在为Web项目使用.NETCore和EFCore。我正在努力如何查询多对多关系。这是我的模型的样子:publicclassBegrip{publicintID{get;set;}publicstringName{get;set;}publicstringDesc{get;set;}[Url]publicstringURL{get;set;}publicICollectionCategories{get;set;}}publicclassCategory{publicintID{get;set;}publicstringName{get;set;}publicICollectionB

c# - 在 .Net Core 中引用另一个项目

我在空白解决方案中有6个项目。我只想将一个项目引用到另一个项目。我在Blog.Web项目中有HomeController。我想访问另一个项目的方法,例如Blog.Services项目中的IOrganizationService。如何在HomeController类中使用IOrganization的方法?为了清楚的洞察力,请看图片。红色标记表示错误.... 最佳答案 看起来您已经将所有内容创建为网站,但我怀疑这些项目中大多数实际上应该是类库(dll),而不是网站。您可能需要重置一些东西!您应该能够右键单击Dependencies节点以

c# - Entity Framework Core 2.0.1 在所有嵌套的相关实体上预先加载

我有一个简单的问题,但似乎找不到解决方法。我正在使用EntityFrameworkCore版本2.0.1,并希望在默认情况下预先加载我的所有实体。例子:publicclassOrder{publicintId{get;set;}publicstringName{get;set;}publicintCustomerId{get;set;}publicCustomerCustomer{get;set;}}publicclassCustomer{publicintId{get;set;}publicstringName{get;set;}publicintAddressId{get;set;

c# - .NET Core 中 HttpListener 的模拟是什么

我正在将应用程序从.NET4移植到.NETCore,但找不到HttpListener类的模拟ErrorCS0246Thetypeornamespacename'HttpListener'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)更新1privatereadonlyHttpListener_httpListener;if(!HttpListener.IsSupported){thrownewNotSupportedException("TheHttpServercannotrunonthisope

c# - IFormFile 始终为 null(带有 MVC/Razor 的 ASP.NET Core)

我有一个ASP.NETCoreMVC应用试图上传IFormFile。但是,IFormFile始终为空。我发现的其他解决方案都没有解决这个问题。我做错了什么?模型publicclassEmailForm{[Display(Name="Addapicture")][DataType(DataType.Upload)][FileExtensions(Extensions="jpg,png,gif,jpeg,bmp,svg")]publicIFormFileSubmitterPicture{get;set;}}ControllerpublicasyncTaskContribute([Bind(

c# - 如何在 asp.net core 中获取 IConfiguration 的实例?

我制作了一个单元测试项目来测试我的webapi,我需要初始化一个Controller,问题是在构造函数中它接收到一个IConfiguration,它由依赖注入(inject)提供并且工作正常。但是当我想手动初始化它时,我没有办法得到这个实例。我正在尝试从同一项目内部的单元测试项目初始化它。Controller看起来像:publicController(IConfigurationconfiguration){_configuration=configuration;} 最佳答案 我可能应该从以下声明开始:在.NetCore应用程序中

c# - 使用 jquery ajax 在 aspx.cs 文件中调用 webmethod

我有一个default.aspx.cs,其中包含我要调用的web方法,我的js文件包含我的jqueryajax。我无法调用网络方法。这是我的default.aspx.cs:protectedvoidPage_Load(objectsender,EventArgse){string[]MyArray=newstring[1];MyArray[0]="MyValue";Grid1D.DataSource=MyArray;Grid1D.DataBind();}[WebMethod]publicDetails[]getDetails(stringcolumnname,stringinputVa

c# - .NET Core 使用配置绑定(bind)到带有数组的选项

使用.NETCoreMicrosoft.Extensions.Configuration是否可以将配置绑定(bind)到包含数组的对象?ConfigurationBinder有一个方法BindArray,所以我认为它会起作用。但是当我尝试它时,我得到了一个异常(exception):System.NotSupportedException:ArrayConvertercannotconvertfromSystem.String.这是我精简后的代码:publicclassTest{privateclassExampleOption{publicint[]Array{get;set;}}[