Should my MVC controller really know about JSON?

后端 未结 7 2111
有刺的猬
有刺的猬 2021-01-30 14:51

The JsonResult class is a very useful way to return Json as an action to the client via AJAX.

public JsonResult JoinMailingList(string txtEmail)
{
        // ...         


        
7条回答
  •  佛祖请我去吃肉
    2021-01-30 15:14

    I'm not sure how big of a problem this actually is, but the "alternative pattern" to follow in ASP.NET MVC would be to write a JSON ViewEngine. This wouldn't actually be that difficult, since the JSON functionality built into the framework will do much of the heavy lifting for you.

    I do think that this would be a better design, but I'm not sure it's so much better that it's worth going against the "official" way of implementing JSON.

提交回复
热议问题