1

I am using ASP.NET MVC / WebAPI and Knockout to generate my views. I am trying to figure out where I should handle formatting, url generation, etc (I would normally do in my controller and return a view model).

Is is an ok practice to have my WebAPI return view models with preformatted data or should I leave that to the caller?

Please note the API is only used by my application

1 Answer 1

2

What I'd suggest is the following:

  • WebApi controller actions provide / consume data (json data) - Http verb actions

  • On your knockout viewmodel it contains methods to get / save etc the json data which is called on document ready to populate the data

  • The default mark-up is created by your MVC view returned from the controller on initial load and then any further can be done dynamically (either inline or templates; native or knockout)

In my opinion the WebApi should not return the full view model. It should only return the data consumed by your view model. The api points should not be implementation specific and allow for knockout consumption as well any other client.

HTH

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.