1

I want to convert this code from this asp.net mvc to asp.net core

[ChildActionOnly]
public ActionResult MyActionThatGeneratesAPartial(string parameter1)
{
    var model = repository.GetThingByParameter(parameter1);
    var partialViewModel = new PartialViewModel(model);
    return PartialView(_partialViewModel); 
}


@{ Html.RenderAction("MyActionThatGeneratesAPartial", "mycontrollerpartial"); }

because I'm more familiar with asp.net mvc, so I don't know what this code looks like in asp.net core

3

2 Answers 2

2

There's 2 way to work-around missing .NET CORE RenderAction functionality:

<div id="dynamicContentContainer"></div>
<script>   
    $.get('@Url.Action("MyActionThatGeneratesAPartial", "mycontrollerpartial")', {id : 1}, function(data){
            $("#myActionContentContainer").html(data);
        });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

There's also this post that explain how incapsulate in a ViewComponent: stevefenton.co.uk/2019/08/…
1

i share a sample code blow this. public class aboutusViewComponent : ViewComponent { private readonly IService _services;

    public aboutusViewComponent(IService<AGWPservices> services)
    {
         _services=services;

    }

    public async Task< IViewComponentResult> InvokeAsync()
    {
        var services = _services.WhereByInclude(f => f.IsActive == true && f.IsDeleted == false && f.UseOnAbout == true,i=>i.Children).ToList()[0];

        return View("_aboutus",services);
    }

  
}

and use on html @await Component.InvokeAsync("services")

it useful sample . and u can run with async

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.