Korpin
Korpin

Reputation: 325

Call a method from Layout.cshtml

I have a question regarding the best way to call a method from Layout.cshtml.

The project is in NET 6.

In Layout.cshtml, I have a button / link (which is in a nav) that opens a modal. The modal allows the user to confirm (or cancel) the deletion of his account.

I have a doubt on what's the best way to call the method that will be used to delete the account given that there is no controller bound to Layout.cshtml.

Is it better to create a controller that will only be used for deleting the account and then redirect on a confirmation page? I plan to do a client validation (in javascript) and a server validation (check if the API call to DB has rightfully deleted the account).

I also read about View Component but I don't think it's relevant in this use case.

Should I use a Partial view? I guess I could put the modal's body in a Partial View, call the method and execute what it need to be done.

For info, I'm not using Identity at all. The delete method will have to connect to a Filemaker database by API.

Thanks in advance!

Upvotes: 0

Views: 545

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28222

In my opinion, I suggest you could consider using JS ajax to call an controller method(like web api controller to do some account related action), then inside this api, you could use Httpclient to call the Filemaker database.

During calling ajax, you could use js to write some logic to confirm if user need to delete or not.

The reason why we don't suggest you directly call the Filemaker database by using ajax is calling the internal api and then call the remote database will be more security.

Upvotes: 1

Related Questions