我最近将我的 web api 从 .Net core 2.2 升级到 .Net core 3.0,并注意到当我将帖子中的枚举传递给我的端点时,我的请求现在出现错误。例如:
我的 api 端点有以下模型:
public class SendFeedbackRequest
{
public FeedbackType Type { get; set; }
public string Message { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
反馈类型如下所示:
public enum FeedbackType
{
Comment,
Question
}
Run Code Online (Sandbox Code Playgroud)
这是控制器方法:
[HttpPost]
public async Task<IActionResult> SendFeedbackAsync([FromBody]SendFeedbackRequest request)
{
var response = await _feedbackService.SendFeedbackAsync(request);
return Ok(response);
}
Run Code Online (Sandbox Code Playgroud)
我将它作为帖子正文发送给控制器的地方:
{
message: "Test"
type: "comment"
}
Run Code Online (Sandbox Code Playgroud)
我现在收到以下错误发布到此端点:
The JSON value could not be converted to MyApp.Feedback.Enums.FeedbackType. Path: $.type | LineNumber: 0 | …
我在使用web api在asp.net中一次更新我的数据库1列时遇到此问题.我试图查询PUT只更新行中的一个值而不是更新那个值并将其余值设置为null.我在控制器之外做了一个单独的模型来接受更新,所以我可以一次做一个.当我db.Entry(user).State = EntityState.Modified;在控制器中点击该行时,它出错了.有什么建议我怎么解决这个问题?
这是我在put方法中使用的单独的ViewModel:
namespace WebAPI.Models.ViewModels
{
public class UserViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器在我的参数中使用ViewModel调用方法:
public HttpResponseMessage PutUser(int id, UserViewModel user)
{
HttpResponseMessage response;
if (db.User.IsInRole("Admin"))
{
try
{
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!UserExists(id))
{
response = new HttpResponseMessage(HttpStatusCode.NotFound);
return response;
}
else
{
throw;
}
}
response = new HttpResponseMessage(HttpStatusCode.NoContent);
return response;
}
Run Code Online (Sandbox Code Playgroud)
这是我的DBContext档案:
public partial …Run Code Online (Sandbox Code Playgroud) 我试图输入反应组件的参数时出错.我想严格键入组件的道具和状态的属性,但是当我使用Redux时,我将mapStateToProps传递给connect函数时出错.
这是组件代码:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import FileExplorer from '../components/file-explorer/file-explorer';
import { ISideMenu, ISideMenuState } from '../models/interfaces/side-menu';
class SideMenu extends Component<ISideMenu, ISideMenuState> {
render() {
return (
<div>
{this.props.fileExplorerInfo !== null &&
<FileExplorer fileExplorerDirectory={this.props.fileExplorerInfo.fileExplorerDirectory}/>
}
</div>
);
}
}
const mapStateToProps = (state: ISideMenuState) => {
return {
fileExplorerInfo: state.fileExplorer
};
};
export default connect<ISideMenu, null, ISideMenuState>(mapStateToProps)(SideMenu);
Run Code Online (Sandbox Code Playgroud)
所以错误发生在这一行:
export default connect<ISideMenu, …Run Code Online (Sandbox Code Playgroud) 我在Visual Studio 2015中遇到了一个新制作的Xamarin.Forms应用程序的问题.我将Droid/iOS项目添加到解决方案中,它给了我一个构建错误,说...
The type or namespace 'App' does not exist in the current namespace
以下是两个错误的位置示例.
Droid项目:
namespace MyApp.Droid
{
[Activity (Label = "MyApp", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new MyApp.App ());
//Error on the above line at MyApp.App ()
}
}
}
Run Code Online (Sandbox Code Playgroud)
iOS项目:
namespace MyApp.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{ …Run Code Online (Sandbox Code Playgroud) 好的,所以我想学习如何打印链表.我有我需要用于列表的所有方法,但我无法弄清楚如何显示节点的值.现在我的main方法中没有任何内容,因为我在主要方法中尝试调用非静态方法时遇到错误.我有一个toString方法,显示列表的内容.我如何调用此toString来显示每个节点的值?任何建议将不胜感激.
这是节点类:
public class LinkedListNode
{
private int data;
private LinkedListNode next;
public LinkedListNode(int data)
{
this.data = data;
this.next = null;
}
public int getData()
{
return data;
}
public void setData(int d)
{
data = d;
}
public LinkedListNode getNext()
{
return next;
}
public void setNext(LinkedListNode n)
{
next = n;
}
}
Run Code Online (Sandbox Code Playgroud)
这是LinkedList类,它包含操作列表的main和方法:
public class LinkedList {
public LinkedListNode head;
public static void main(String[] args) {
LinkedList l = new LinkedList();
l.insertFront(0);
System.out.println(l.toString());
}
public LinkedList() …Run Code Online (Sandbox Code Playgroud) 所以我遇到了这个奇怪的问题,我试图显示从我的网络 API 收到的 pdf,但 pdf 在 Chrome 的新浏览器选项卡中显示为空白(IE 没有显示任何内容,但它 console.logs ajax 成功打回来)。
API 将其发送回我的 ajax 请求,如下所示:
public async Task<HttpResponseMessage> GetPdf(PdfModel model)
{
var pdf = await _pdfManager.GetPdfAsync(model);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(pdf);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "MyPdf.pdf";
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
}
Run Code Online (Sandbox Code Playgroud)
这是调用另一个 API 来获取 pdf 的 GetPdfAsync 方法。当我使用 Postman 调用具有相同模型的 api 时,我确实得到了一个作为响应显示的 PDF,所以我知道效果很好。
public async Task<byte[]> GetPdfAsync(PdfModel, CancellationToken ct = new CancellationToken())
{
using (var client = new HttpClient())
{
client.BaseAddress …Run Code Online (Sandbox Code Playgroud) 我试图从链表中删除特定节点.我试图调用我的方法removeNode,但是当我调用它来获取用户输入时它给了我这个错误.任何关于如何解决这个问题的建议将不胜感激!
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at LinkedList.removeNode(LinkedList.java:123)
at fileIn.<init>(fileIn.java:22)
at fileIn.main(fileIn.java:13)
Run Code Online (Sandbox Code Playgroud)
LinkedList类:
import java.util.Scanner;
public class LinkedList {
public LinkedListNode front;
public LinkedList() {
this.front = null;
}
public void insertBack(String data)
{
if(front == null){
front = new LinkedListNode(data);
}
else{
LinkedListNode newNode = new LinkedListNode(data);
LinkedListNode current = front;
while(current.getNext() != null){
current = current.getNext();
}
current.setNext(newNode);
}
}//end insertBack
public void addAfter(LinkedListNode spot, String data)
{
LinkedListNode newNode;
newNode = …Run Code Online (Sandbox Code Playgroud) 我有一个问题,如果我单击一个菜单项或覆盖(不确定这是一个选项,还是反应组件可能),我似乎无法确定我的应用栏的LeftDrawer未关闭的位置.理想情况下,我希望两个选项关闭抽屉.提前感谢您抽出宝贵时间来看看这个!
这是我用来切换打开LeftDrawer的Navbar类:
// Dependencies
import React from 'react';
//Comonents
import LeftDrawer from './left-drawer.jsx';
// Styles
import './nav-bar.scss';
import AppBar from 'material-ui/AppBar';
class NavBar extends React.Component {
constructor(props){
super(props);
this.state = {
open: false
};
}
toggleDrawer(){
this.setState({
open: !this.state.open
});
}
render(){
return (
<div className='nav-bar'>
<AppBar title='My App' onLeftIconButtonTouchTap={() => this.toggleDrawer()}/>
<LeftDrawer open={this.state.open} onToggleDrawer={this.toggleDrawer.bind(this)} />
</div>
);
}
}
export default NavBar;
Run Code Online (Sandbox Code Playgroud)
这是带有MenuItems的LeftDrawer类:
// Dependencies
import React from 'react';
import { Link } from 'react-router-dom';
// Styles
import Drawer …Run Code Online (Sandbox Code Playgroud) 我在将父组件的状态绑定到孩子的状态时遇到问题。看一下代码:
父组件:
class ParentForm extends React.Component {
constructor(){
super();
this.state = {
showDialog: false
};
}
toggleDialog() {
this.setState({showDialog: !this.state.showDialog});
}
return (
<div >
<Button color='primary' onClick={() => this.toggleDialog()}></Button>
<MyDialog open={this.state.showDialog}/>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
子组件:
export default class MyDialog extends Component {
constructor(props){
super(props);
this.state = {
open: this.props.open
};
}
handleRequestClose = () => {
this.setState({ open: false });
};
render() {
return (
<div>
<Dialog
fullScreen
open={this.state.open}
onRequestClose={() => this.handleRequestClose()}
transition={<Slide direction="up" />}
>
<DialogTitle>{'Title'}</DialogTitle>
<DialogContent>
<DialogContentText> …Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法来运行一些代码(我设置连接字符串,DI和其他配置)当我的Azure功能启动时.所以现在,它在生成的function.json中调用Run方法作为入口点:
"entryPoint": "MyFunctionApp.MessageReceiver.Run"
Run Code Online (Sandbox Code Playgroud)
此Run方法使用EventHubTrigger并处理传入的消息,如下所示:
[FunctionName("MessageReceiver")]
public static void Run([EventHubTrigger("eventHubName", Connection = "eventHubConnection")]string message, TraceWriter log)
{
if (string.IsNullOrWhiteSpace(message))
{
log.Info($"C# Event Hub trigger function processed a message: {message}");
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在调用Run方法之前在初始启动时运行一些代码?或者有没有办法声明我可以在此类之前调用的入口点,然后调用Run()并以某种方式传入触发器?我试图找到一种方法来避免像设置布尔属性,以查看应用程序是否已启动等hackish.
c# ×3
javascript ×3
reactjs ×3
java ×2
linked-list ×2
material-ui ×2
react-redux ×2
ajax ×1
asp.net ×1
azure ×1
dbcontext ×1
input ×1
jquery ×1
nodes ×1
pretty-print ×1
put ×1
redux ×1
tostring ×1
typescript ×1
xamarin ×1
xamarin.ios ×1