开发者

How to call stored proc from ASP.Net MVC stack via the ORM & return them in json?

开发者 https://www.devze.com 2022-12-24 18:39 出处:网络
i\'m a total newbie with asp.net mvc and here\'s my jam: i have a 3 level list box which selection on box A shows options on box B and selection on box B will show the options for box C.

i'm a total newbie with asp.net mvc and here's my jam:

i have a 3 level list box which selection on box A shows options on box B and selection on box B will show the options for box C.

I'm trying to do the whole thing in asp.net MVC and what i see is that the nerd dinner tutoria开发者_JS百科l uses the ORM method.

so i created a dbml to the database and drag the stored proc inside. i create a datacontext object but i don't quite know how to connect the result from the stored proce which should be multiple rows of data and make it into a json.

so i can keep all the json data inside the html page and using jquery i could make the selection process faster.

i don't expect the data inside the three boxes to change so often thus i think this method should be quite viable.

Questions:

  1. So how do i get the stored proc part to return the data as json?

  2. i've noticed some tutorial online that the json return result part is at the controller and not at the model end. Why is that?

Edit FYI, i find what i mostly wanted to do here. For the json part, i referenced here.


  1. Return a JsonResult from your controller action. You may need to coerce the result from your stored procedure into a C# class serializable to Json.

  2. Json conversion should be done in the controller because it's not really part of the domain. More a DTO in the MVVM (Model-View-ViewModel) style.

0

精彩评论

暂无评论...
验证码 换一张
取 消