Calling another controller action from view (@Html.action())

ZAZ
ZAZ
Vote:
 

EPiServer CMS version: 11

Hi 

   I am trying to call another block controller Index method from view of the page. 

Here is the code which calls the action method of the FileuploadBlock controller.

@Html.Action("Index", "FileuploadBlock", new
   {
       cuurentBlock = Model.CurrentPage.FileuploadBlock,
       filehandles = "MessageCreate.Filehandles"
   })

Here is the Index method of the FileuploadBlock controller

public ActionResult Index(FileuploadBlock currentBlock, string fileHandler)
        {
            var viewModel = new FileuploadViewModel(currentBlock);
            xxxx
}

It work good in success flow but if modelstate is not valid and I have to show the page view again, then it gives me this error:

EPiServer.Core.TypeMismatchException: 'The routed data is of type 'x.Models.Pages.NewMessagePage' and the binding context 'currentContent' is null, cannot bind any value to type 'x.Models.Blocks.FileuploadBlock'.'

Hope someone can answer this.

#215768
Jan 13, 2020 12:40
Vote:
 

Probably you are looking for a ContentArea Property in your block, where other blocks could be dropped. Aren't you?

#215791
Jan 14, 2020 8:59
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.