This is a migrated thread and some comments may be shown as answers.
New Form - how to include antiForgeryTokens
5 Answers 40 Views
This is a migrated thread and some comments may be shown as answers.
Bas
Top achievements
Rank 1
Bas asked on 23 May 2020, 04:31 PM
How do we include antiForgeryTokens to the submit action?

5 Answers, 1 is accepted

Sort by
0
Bas
Top achievements
Rank 1
answered on 23 May 2020, 10:15 PM
A better question would be how to include hidden fields in the form?
0
Ivan Danchev
Telerik team
answered on 28 May 2020, 07:59 AM

Hello Bas,

At present, there is no built-in support for hidden fields. For a hidden field value to be sent on form submission, it can be appended to the form with jQuery, e.g.:

$(document).ready(function () {
	$('form').append("<input type='hidden' data-bind='value: Description' name='Description' value='123' />");
})

I've logged a feature request on your behalf in our Feedback Portal: https://feedback.telerik.com/aspnet-core-ui/1469243-add-support-for-hidden-fields-to-the-form

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
Bas
Top achievements
Rank 1
answered on 29 May 2020, 09:40 PM

Thanks Ivan. I finally got a chance to test your suggestion, and it worked fine.

I ended inserting the forgery tokens and the other hidden fields this way:

$(document).ready(function () {
     $('*[name*=RequestVerificationToken]').each(function (index) {
 if(index === 0) {
             $("#facilityForm").append($(this));
          }
      });
      $("#facilityForm").append($('@Html.HiddenFor(m => m.Id)'));
}
0
Andy
Top achievements
Rank 1
answered on 03 Jul 2020, 01:15 PM

Thanks Bas.  This worked for me, once I put a trailing ')' at the very end.  Should need to do this, it should just work out the box.

 

Andy

0
Ivan Danchev
Telerik team
answered on 08 Jul 2020, 09:12 AM

Hello Andy,

Consider casting your vote for the previously linked feature request: https://feedback.telerik.com/aspnet-core-ui/1469243-add-support-for-hidden-fields-to-the-form

The more votes it acquires the higher its chances are for getting approved for implementation.

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.
Tags
Form
Asked by
Bas
Top achievements
Rank 1
Answers by
Bas
Top achievements
Rank 1
Ivan Danchev
Telerik team
Andy
Top achievements
Rank 1
Share this question
or