Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

When Does EPiServer validate XFormPostedData

Vote:
 

Hello,

I'm not having much luck in trying to figure this out. We're on EPiServer 7.5 and I am posting a form from a Block by using code similar to that found here http://cjsharp.com/blog/2013/04/11/creating-a-xform-block-in-episerver-7-mvc-with-working-validation-updated/. This all works okay but in my XFormPost method I want to check if the ModelState is valid before I do anything else.

e.g.

Snippet

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult XFormPost(XFormPostedData xFormpostedData)
        {
            ActionResult thisResult;

            if (Request.UrlReferrer == null || string.IsNullOrEmpty(Request.UrlReferrer.Query) || !this.ModelState.IsValid)
            {
                thisResult = _xformHandler.HandleAction(this);
                return thisResult;
            }

            // Do other stuff
        }


At this point the ModelState is always true. If I run _xformHandler.HandleAction(this) it seems to set the ModelState correctly but I don't really know what else this does. For example I don't want it to post the form data. Can anyone clarify what the HandleAction method does and if there is another (more correct way) of validating the model at this point?

Thanks in advance!

#196086
Aug 17, 2018 16:23
Vote:
 

It looks like the following command will validate the model:

Snippet

TryValidateModel(xFormpostedData);
#196129
Aug 20, 2018 10:03
* 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.