Try our conversational search powered by Generative AI!

Multiple episerver form container views?


Disclaimer: apparently I cannot post links on the forum cause my account hasn't associated to a company

I am following the guide regarding custom forms on develop guides.

It tells you to copy FormContainerBlock.ascx from the zip file to your configured viewpath. It also tells you to use the filename as is. And the controller from which you inherit (FormContainerBlockController) actually has hardcoded the viewpath.

PartialViewResult partialViewResult = this.PartialView("FormContainerBlock", (object) currentBlock);

So you cannot really have multiple views for the formcontainer. Why not have it like the elements that the view will corrospond to the typename of the FormContainer model (or maybe the controller)? Also it could fall back to using FormContainerBlock.ascx if no other is available.

Was this changed, cause there are forum thread here on world that actually states that it load a view corrosponding to the model. But it could also be that an action filter hooks in and change the view path ...

May 20, 2020 12:08

This isn't something I've done, but you could override the PartialView method when implementing the controller for your custom form.

Let's say, for example, you custom form was given the original name CustomFormContainerBlock then your controller could look like this:

	AvailableWithoutTag = true,
	Default = true,
	ModelType = typeof(CustomFormContainerBlock),
	TemplateTypeCategory = TemplateTypeCategories.MvcPartialController)]
public class CustomFormContainerBlockController : FormContainerBlockController
	protected override PartialViewResult PartialView(string viewName,object model)
		return base.PartialView(nameof(CustomFormContainerBlock), model);
Jun 08, 2020 20:23

Thank you it worked ... why didn't I think of that :)

Jun 09, 2020 9:18
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.