This is a migrated thread and some comments may be shown as answers.

Forms and Razor Pages Throws Exceptions

3 Answers 192 Views
Form
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Veteran
Andy asked on 29 Jun 2020, 05:16 PM
Are Razor Pages supported by the Forms widget.  I keep getting an unhandled exception caught in the middleware after the Exception Handler has completed and nothing is returned just the <div></div> that I placed around it

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 02 Jul 2020, 02:57 PM

Hello Andy,

The Form can be used in RazorPages. Attached you can find a sample RazorPages project, in which a Form is initialized.

Regards,
Ivan Danchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Andy
Top achievements
Rank 1
Veteran
answered on 03 Jul 2020, 12:43 PM

Hi Ivan, thanks for the reply. 

A key thing in allowing the form to be rendered was the .FormData(TModel model) call.  Without it there's nothing on the screen.

However the next issue is the Post call - its returning an error 400.  I would assume that since the form values will be passed using a [BindProperty]  then the signature of my method should be:

    IActionResult OnPost()

Digging deeper I've found that the post is failing due to the anti forgery token not being passed in.  With the Grid component all I had to do was add a .Data("forgeryToken") method.  Is there a similar method for Form?

 

Thanks,

Andy

0
Andy
Top achievements
Rank 1
Veteran
answered on 03 Jul 2020, 01:20 PM
Tags
Form
Asked by
Andy
Top achievements
Rank 1
Veteran
Answers by
Ivan Danchev
Telerik team
Andy
Top achievements
Rank 1
Veteran
Share this question
or