Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

TypeMismatchException

Vote:
 

I have a page with local block

[ContentType(GUID = "d9298163-9046-4bd1-9ff1-81e5abb83a80", AvailableInEditMode = true)]
public class StartPage : BasePageData
{
private const string LeftNavigationMenu = "Left Navigation";

[CultureSpecific(true)]
[Display(GroupName = SystemTabNames.Content, Order = 50)]
public virtual ContentArea MainContentAreaTop { get; set; }

[CultureSpecific(true)]
[Display(GroupName = SystemTabNames.Content, Order = 60)]
public virtual ContentArea MainContentArea { get; set; }

[Display(GroupName = FooterSettingsBlock.FooterTab, Order = 100)]
public virtual FooterSettingsBlock FooterSettings { get; set; }

 

And I try to render partial view and send to view FooterSettings: 

 

@{
Html.RenderPartial("Shared/Footer", @Model.SiteSettings.MySiteSettingsPage.SiteStartPage.ToPage<StartPage>().FooterSettings);
}

 

I have a logic in StartPageController: 

public class StartPageController : BasePageController<StartPage>
{[HttpPost]

public ActionResult Subscribe(SubscriptionViewModel model)
{
return Redirect("/");
}
}

 

and try to call this method from partial Footer view:

@model Valtech.Core.Website.Models.Blocks.FooterSettingsBlock

<div>
<h3>@Html.PropertyFor(m => m.SubscriptionHeading)</h3>

@Html.Partial("shared/Subscription", new SubscriptionViewModel {CurrentBlock=Model})
</div>

 

Subscription partial view:

@model Valtech.Core.Website.Models.ViewModels.SubscriptionViewModel

@using (Html.BeginForm("Subscribe", "StartPage", FormMethod.Post, new { id = "subscribeForm" }))
{
<input name="Email" id="userEmail" type="text" placeholder="@Model.CurrentBlock.EnterEmailText"/>
<a href="javascript:document.getElementById('subscribeForm').submit()">@Model.CurrentBlock.SubmitText</a>
}

 

When I click my link, I get TypeMismatchException and this stackTraice:

[TypeMismatchException: The existing IContentData instance is of type 'Castle.Proxies.ExtaviaStartPageProxy' and does not match the requested type 'Valtech.Core.Website.Models.Blocks.Extavia.ExtaviaFooterSettingsBlock'.]
   EPiServer.Web.Mvc.ContentDataModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +718
   System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +33
   System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +493
   System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +283
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +675
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +484
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +153
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +839839
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) +166
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag) +27
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) +50
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) +166
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +826929
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) +166
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) +27
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +401
   Valtech.Core.Website.Controllers.ExtaviaStartPageController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) in c:\Projects\Msliv\trunk\EPiServerCMS\branches\Extavia\Valtech.Core.Website\Controllers\ExtaviaStartPageController.cs:11
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) +787034
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) +166
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) +27
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +343
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12639247
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288


Could somebody help me with this problem?
#83277
Mar 28, 2014 13:01
Vote:
 

Not sure about Html.RenderPartial(). Haven't tried it with local blocks.

Try following:

@Html.PropertyFor(m => m.SiteSettings.MySiteSettingsPage.SiteStartPage.ToPage<StartPage>().FooterSettings)

    

Then it depends on what you need to accomplish.

1) If you don't need a controller for your block type -> then just name your view tha same name as block - FooterSettings.cshtml. This will tell EPiServer to skip any controllers and render view directly.

2) If you need custom logic (like construct custom view model) you may need a controller for this block.

public class FooterSettingsBlockController : BlockController<FooterSettingsBlock>
{
    public ActionResult(FooterSettingsBlock currentBlock)
    {
        return PartialView(".....", model);
    }
}

    

Keep in mind that using second choice you need to rename view in order to EPiServer understand that you need a controller for your block. A good practice is to start those partial views with underscrore - "_" -> "/Views/Shared/_FooterSettings.cshtml".

#83616
Mar 28, 2014 16:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.