How to execute the viewcomponent and read the viewcomponent's parameters from the controller?

270 Views Asked by At

I am using the below code to execute view component in .cshtml

@await Component.InvokeAsync("FileUpload",Model)

Inside that view component, there is a file uploader. enter image description here

After select a file when I click Upload button ( Upload button is also inside the viewcomponent) debug goes to controller. My controller's action goes like below

[HttpPost]
        public async Task<IActionResult> Index(ToolModel model)
        {
           
            model.FileUploadFileFormats = "application/pdf";
            model.FromFileType = FileTypes.pdf;
            model.ToFileType = FileTypes.doc;

           
            return View(FullPathsOfViews.PdfToWord, model);
        }

After executing above then next goes to Viewcomponent methods. After that coding path exits. Instead that I want to bring the result from viewcomponent back to the controller.

[HttpPost]
        public async Task<IActionResult> Index(ToolModel model)
        {
           
            model.FileUploadFileFormats = "application/pdf";
            model.FromFileType = FileTypes.pdf;
            model.ToFileType = FileTypes.doc;

           VAR Result = Component.InvokeAsync("FileUpload",Model) //Something like this

            return View(FullPathsOfViews.PdfToWord, model);
        }

How to achieve this?

0

There are 0 best solutions below