Hamid Mosalla Web Development And . Net Core has a set of action results which are intended to facilitate the creation and formatting of bitcoin url formats data. Without a well formed correct response, our application cannot work correctly and efficiently. In this post I’m going to explain how Asp.
Net Core action results works and what kind of response they return to the client. Also I’m going to discuss when and why to use them and how you can create you own custom action results. Also I’m going to introduce some ideas and opinions about correct usage and best practices that might be of benefit. Action results form previous version of Asp. I could go with explaining the action results in accordance with this picture, but I thought categorizing it based on usability helps with remembering and explanation.
Also because some of their characteristics can be the same. As you can see if the framework didn’t do this, we needed to do a lot of plumbing work and our controller would have become harder to read. By the way what the framework does here is actually called Command Pattern. So they can’t be newed up and returned like other action results. I have a page that submit a Product, I have a main page for it. Now I want to add different brand of the same product with some info about it, I have a button to add more brand of products.
I can either submit the product and add brand to it using a normal view, or I can add a button and a modal containing the fields needed for submitting new brands. But how should I do it? What if there was a different model for the data involved with it? Or some kind of calculation was involved? Maybe we want to reuse our business logic or refresh our the HTML part of the page that are loaded with view component, can we do that?
According to CQS principle commands shouldn’t return anything. There is one other kind of action result that return null but it doesn’t return 200 HTTP status code, but 204. If we want to return a POCO class for an action, we can. Primitive Types Result You can also return string or int or any other kind of primitive types and the framework tries its best to convert it to a response that is pertinent to the current type. Here we see that result is converted to JSON, hmm.