Asp.Net Razor with Json

2

I have a question and I already researched several sites but I did not get the answer. I develop systems in .Net with C # in the MVC standard and use the on-screen presentation in the traditional View with Razor form.

It turns out that I have noticed that several web systems made available lately have presented more and more a user experience equal to a Desktop application, that is, with almost no Reloads per request and more interactivity with the events of the fields.

Many of these systems use Knockout, Vue, Aurelia and especially AngularX in their Views, or rather use only the MC and V is on behalf of another technology.

Now comes my question, since I do not master any of these technologies (yet), with your experience, what would be the best way to work with Views so that I could build systems with a more user-friendly experience next to those provided by the technologies previously mentioned while maintaining my MVC development standard with Razor? Because of the power that Views generated with Razor offers, very probably I should not be using any features that this tool can make available! - So I could observe one of the things that "I should" working to get at the expected result is working with Json (so far so good) as if my application were a Web API - am I right?

I hope to have been clear on the presentation of my doubt.

Thanks in advance for the force!

    
asked by anonymous 05.04.2017 / 18:21

1 answer

2
  

So I could observe one of the things I "should" work to get at the expected result is to work with Json (so far) as if my application were a Web API - am I right?

Better yet: work with the Web API itself. The Web API came up exactly in its realization: how to make the MVC system work without relying on the presentation layer?

  

What would be the best way to work with Views so that I could build systems with a user experience closer to those provided by the technologies mentioned above while maintaining my MVC development standard with Razor?

First, developing the methods that respond to the new presentation layer within the MVC system itself. Then migrating this structure to a pure Web API system. -10-de-Sept-2016 / "> I have a course that explains how to do it , if you are interested (the menu is the same).

That is, given a method that normally returns a View :

public ActionResult DevolveView()
{
    ...
    return View(objetos);
}

You make a copy of this method to return a structured JSON:

public JsonResult DevolveView()
{
    ...
    return Json(objetos, JsonRequestBehavior.AllowGet);
}

And then create a separate Controller for these new methods using JSON:

public MeuControllerApi : ApiController
{
    public IHttpActionResult DevolveView()
    {
        ...
        return Ok(objetos);
    }
}

This is just a suggestion. Ideally, you should take a more dense tutorial to understand how this migration works.

    
05.04.2017 / 18:36