2

I have view component1:

<form class="form-horizontal">
    <input type="text" name="ip1" class="form-control"/>
    <input type="submit" name="btnSubmit" class="btn btn-default" />
</form>

and view component2:

<form class="form-horizontal">
    <input type="text" name="ip1" class="form-control"/>
    <input type="submit" name="btnSubmit" class="btn btn-default" />
</form>

Two view components is in the same page. But I don't know how to handle post request inside each view component. And how to post a model to a view component? Example code behind or similar:

 public class Component1ViewComponent : ViewComponent
 {
    public Component1ViewComponent()
    {

    }

    public async Task<IViewComponentResult> InvokeAsync(bool isPost)
    {
        if (isPost)
        {
            //handle post request and get model value here
        } else
        {

        }
        return View(model);
    }
}

1 Answer 1

2

ViewComponents are not a http request endpoints, so what you are trying to do is not possible. View components come into picture only when a view is being generated.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I need that because I have some ideal for project structure. I will find another way.

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.