Is it possible to return the back-end model for react as a JSON file or a simple array for the data source?
For example by a function with Axios and fetch?
Is it possible to return the back-end model for react as a JSON file or a simple array for the data source?
For example by a function with Axios and fetch?
SaeedP, what are you trying to do exactly? Are you trying to call an Web API action from a React component? If so, this is covered in every beginning level React tutorial.
SaeedP
But this is not working!
SaeedP, stop with the generic "not working!". Explain the expected results and what is "not working!" Share enough code the community can run to reproduce the unexpected behavior.
Again, fetching JSON and updating state is found in every
beginning level React tutorial. The code you've share above is similar to most of your posts where it looks like you mindlessly copied code from an internet blog without taking the time to understand what the code does. You really need to set aside the
time to learn the basics. This does not happen in one day.
At the same time you did not include the data model or the action that returns the data model. The community cannot answer the question anyway...
Below is a React component that uploads image files (your other post) and shows a list of files. Keep in mind, the React code is not production ready and not well written but it should give you an idea of how to render a list and how to reference an image.
public class Image
{
public int ImageId { get; set; }
public string FileName { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string ContentType { get; set; }
public DateTime DateModified { get; set; }
}
public class ImageData
{
public string Description { get; set; }
public IFormFile File { get; set; }
}
Again thank you for your help. As always you helped me.
About your words:
Many of you have the chance to work in large programming companies and learn many things from the coworkers. But about me, that wasn't true and never work in a large company.
I have some questions about your code:
Couldn't we write image class and image data class? Why we create them in two separate classes?
In this way, do we save images in the temp folder? where we save the images?
in this way, do we return JSON value in fileIdList?
Many of you have the chance to work in large programming companies and learn many things from the coworkers. But about me, that wasn't true and never work in a large company.
You are right, many forum members are on development teams. We have code reviews and we provide feedback similar to these forums. The difference is team member typically follow the advice and take the time to learn the concepts. I don't get the same feeling
when reading your posts.
SaeedP
Couldn't we write image class and image data class? Why we create them in two separate classes?
The code examples uses a view model. I explained
this code sample in your other thread. View model patterns are covered extensively in the
Getting Started links I keep asking you to go through. Very simply, the ImageData view model contains the only two user inputs, file and description.
SaeedP
In this way, do we save images in the temp folder? where we save the images?
I wrote the following in your other thread, The files are saved in a temp directory. You'll need to figure out how to organize the files. The file upload code comes directly from
the official file upload docs which also explains file upload security. A link provided in your previous thread.
Again, it is up to you to come up with design to organize the files that makes sense for your application.
SaeedP
in this way, do we return JSON value in fileIdList?
I'm not sure what you are asking. The fileIdList[] contains the the JSON object below. You can see the JSON response by opening the browser's dev tools and simply viewing the response.
I'm not sure what you are asking. The fileIdList[] contains the the JSON object below. You can see the JSON response by opening the browser's dev tools and simply viewing the response.
I mean can I use fileIdList as a data source for components?
I mean can I use fileIdList as a data source for components?
I'm not sure how to answer your question. fileIdList[] is an item in the component's state. When state changes the React framework updates the associated DOM elements. I guess you can consider fileIdList[] or any of the state items a source of data.
Dude, read the docs and go through a few tutorials.
Member
21 Points
246 Posts
Data model as a json data source for react
Jan 21, 2021 05:12 PM|SaeedP|LINK
Hello,
Is it possible to return the back-end model for react as a JSON file or a simple array for the data source?
For example by a function with Axios and fetch?
Is this correct:
But this is not working!
thanks,
All-Star
52981 Points
23580 Posts
Re: Data model as a json data source for react
Jan 21, 2021 08:06 PM|mgebhard|LINK
SaeedP, what are you trying to do exactly? Are you trying to call an Web API action from a React component? If so, this is covered in every beginning level React tutorial.
SaeedP, stop with the generic "not working!". Explain the expected results and what is "not working!" Share enough code the community can run to reproduce the unexpected behavior.
Member
21 Points
246 Posts
Re: Data model as a json data source for react
Jan 21, 2021 09:24 PM|SaeedP|LINK
Yes, I want to use a component and it needs a JSON data source.
For a day I'm looking forward to how to convert data to JSON.
Also, I changed a bit the function:
I used a method, but still, nothing happens!
All-Star
52981 Points
23580 Posts
Re: Data model as a json data source for react
Jan 21, 2021 11:10 PM|mgebhard|LINK
Again, fetching JSON and updating state is found in every beginning level React tutorial. The code you've share above is similar to most of your posts where it looks like you mindlessly copied code from an internet blog without taking the time to understand what the code does. You really need to set aside the time to learn the basics. This does not happen in one day.
At the same time you did not include the data model or the action that returns the data model. The community cannot answer the question anyway...
Below is a React component that uploads image files (your other post) and shows a list of files. Keep in mind, the React code is not production ready and not well written but it should give you an idea of how to render a list and how to reference an image.
Member
21 Points
246 Posts
Re: Data model as a json data source for react
Jan 22, 2021 05:45 AM|SaeedP|LINK
Again thank you for your help. As always you helped me.
About your words:
Many of you have the chance to work in large programming companies and learn many things from the coworkers. But about me, that wasn't true and never work in a large company.
I have some questions about your code:
thanks,
All-Star
52981 Points
23580 Posts
Re: Data model as a json data source for react
Jan 22, 2021 12:49 PM|mgebhard|LINK
You are right, many forum members are on development teams. We have code reviews and we provide feedback similar to these forums. The difference is team member typically follow the advice and take the time to learn the concepts. I don't get the same feeling when reading your posts.
The code examples uses a view model. I explained this code sample in your other thread. View model patterns are covered extensively in the Getting Started links I keep asking you to go through. Very simply, the ImageData view model contains the only two user inputs, file and description.
I wrote the following in your other thread, The files are saved in a temp directory. You'll need to figure out how to organize the files. The file upload code comes directly from the official file upload docs which also explains file upload security. A link provided in your previous thread.
Again, it is up to you to come up with design to organize the files that makes sense for your application.
I'm not sure what you are asking. The fileIdList[] contains the the JSON object below. You can see the JSON response by opening the browser's dev tools and simply viewing the response.
Member
21 Points
246 Posts
Re: Data model as a json data source for react
Jan 22, 2021 06:33 PM|SaeedP|LINK
I mean can I use fileIdList as a data source for components?
All-Star
52981 Points
23580 Posts
Re: Data model as a json data source for react
Jan 22, 2021 08:04 PM|mgebhard|LINK
I'm not sure how to answer your question. fileIdList[] is an item in the component's state. When state changes the React framework updates the associated DOM elements. I guess you can consider fileIdList[] or any of the state items a source of data.
Dude, read the docs and go through a few tutorials.