@Html.Action in Asp.Net Core

后端 未结 9 2130
说谎
说谎 2020-11-27 19:25

Where is @Html.Action in Asp.net Core? I can see @Html.ActionLink but not a direct call to an Action as before.

Was it replaced by ViewComp

9条回答
  •  青春惊慌失措
    2020-11-27 19:56

    @Html.Action was replaced by ViewComponents. I dislike ViewComponents for multiple reasons.

    However I am using alternative pattern to @Html.Action

    First I create Action on controller that is returning partial view with a content that I want to display in page i.e.

        [HttpGet]
        public async Task GetFoo()
        {
            return PartialView("_Foo", new Foo());
        }
    

    Then I place div on page where the foo view should be loaded and include IIFE at the bottom of that page. I.e. code bellow will load GetFoo view and then insert that html to div with id foo-view.

    You may also want to display spinner while view is beign fetched from server.

提交回复
热议问题