Qiuzman
Qiuzman

Reputation: 1761

How to connect MS SQL from VueJS and ASP.Net Core Razor pages

I am using Vue via the CDN to build a SPA. The backend of my website uses ASP.NET Core. The main vue spa page is initialized in a razor page and all the components are imported there using html.partial. So far its working great however I need to connect to the database and pull data and also update the database. I cannot find any simple examples or tutorials of how to query a MS SQL database with entity framework in a vue SPA to pull data for my components or update a MS SQL database with user input from forms on the SPA. Although I am new to Vue and ASP.Net The purpose of the SPA is to reduce the need to reload the page so I am curious how this can be done without reloading and keeping the natural SPA feel yet still interact with the database? For security, I set up authentication already and a login page (razor page) which once logged in redirects to the SPA.

Upvotes: 1

Views: 1321

Answers (1)

Fei Han
Fei Han

Reputation: 27825

You can implement and expose endpoints for querying SQL db with entity framework in backend Web API, then you can consume the API(s) and query data by making http request(s) using Axios etc from your Vue component.

For more information about "Using Axios to Consume APIs", please check this doc:

https://v2.vuejs.org/v2/cookbook/using-axios-to-consume-apis.html#Base-Example

Upvotes: 2

Related Questions