Evgeniy175 Evgeniy175 - 1 month ago 9
ASP.NET (C#) Question

ASP.net Core: Is it normal to call method of different controller from view?

I have 2 controllers:

FirstController
and
SecondController
.

First controller contains GET method
GetFirstData
for send some data.

Second controller contains similar method
GetSecondData
for send different data.

I also have 2 views Index.cshtml for each controller.

I know that call
GetFirstData
method from Index.cshtml view is normal. But is it good to call
GetSecondData
method from Index.cshtml of
FirstController
? E.g. using AJAX with
@Url.Action("GetSecondData", "Second")

Answer

Yes, you can do like this. If you are using Ajax to call that method, there wouldn't be any problem.