How do I submit a form to an MVC controller action using a blazor EditForm component? - asp.net-core

Using blazor I would like to submit the form to an MVC controller action once validation has taken place. Can I make the form behave like a regular form? The following doesn't work because the action attribute is ignored.
<EditForm EditContext="#_modelContext" OnSubmit="HandleValidSubmit" action="/" method="post">
The form values tell the controller what file send to the response stream.
I don't see away to bypass the behaviour of EditForm. Is this possible?

Related

Net Core 6 - posting between razor pages

Is there a way to post between razor pages without disabling the Anti-forgery Token? I appreciate that sounds stupid, but what I'd like the user to be able to do is submit a mini version of the contact us form on one page and the submit action takes them to a different razor page where they can continue to fill in the rest of the form. It's essentially so we can include a mini contact us form in the footer of all pages as a view component. The view component can't handle the post because there is no endpoint for the view component. Whereas this could probably be achieved by carrying the form data on the query string, that then exposes their name/email data which is undesirable. Adding the [IgnoreAntiforgeryToken] attribute on the contact us page works, but is there a way to make it work without removing the validation/checks?

How to load Partial Views using Radio button in mvc4 asp.net razor?

I have two registration types. One is Individual and second as Business type registration.
I have two radio buttons. I have used Html Helper for this. When I click on first radio button
the individual partial view should be loaded. How can I achieve this using ap.net mvc4 razor
Use AJAX to make a request to the controller within a radio button's change function. In the controller action with an HttpPost or HttpGet decoration, you would return a partial view. Within your ajax response you would recieve it as dataType:'html' and place the result inside of a div.
Google is your best friend when you're learning.

DataAnnotations with html submit form

If I want to submit a form using jQuery Ajax from the client, can I do any DataAnnotations inside that HTML submit form as opposed to a Html.BeginForm or Ajax.BeginForm?

how can I use the fileupload helper when it is loaded in another page using the load jquery method?

I have the following problem, one page load in one of his div using the Load method from Jquery Ajax another page that use the FileUpload Asp.net Helper. Alone that page Works fine, but inside this div the upload button apparently calls the hosting page, not the page that original has the helper.
In consecuence, How can correctly use the helper loaded from another page?
In a scheme I think that this is happening:
And I want this to happen, but don't know how to do it:
The upload button submits the form. It will be submitted to whatever location is specified in the action attribute of the form. Therefore you should set the action attribute value to the page that you want the form to post to.
This will be easier to manage if you set includeFormTag to false. It is true by default:
#FileUpload.GetHtml(
initialNumberOfFiles: 1,
allowMoreFilesToBeAdded: false,
includeFormTag: false,
uploadText: "Upload",
name: "Upload1"
)
You will then need to provide your own form tag. Make sure you include the correct enctype for managing file uploads:
<form action="somePage" method="post" enctype="multipart/form-data">
...

:remote => true/data-remote on a form loaded via ajax

In my Rails app, I have a form that is loaded via Ajax using jQuery load method.
function load_sales_form(product_id) {
$("#sales_form").load("<%= url_for(:action => :show_sales_form) %>"/ + product_id);
}
The loaded form has a form_for tag with the :remote => true option and it does add the data-remote="true" attribute to the form.
But the form isn't submitted using Ajax when the user clicks the submit tag button. It works fine if the form is loaded in the standard, non-ajax way, but it the form is loaded via ajax after the document is ready, is does not submit using ajax, it submits as a standard form.
From what I studied so far, this happens because the rails.js file (which contains the stuff that allow data-remote forms to be submitted via ajax) does not apply it's features to html content loaded via ajax.
Is it possible to force rails.js file to apply it's features to content loaded via Ajax?
Same situation here. I found a solution.
Not the dynamic loading, but incorrect triggering of submit event was the cause in my case.
I had a Bootstrap modal with data-target and href attributes set. This causes the content inside a .modal-body to be loaded via AJAX from address specified in href.
The modal was pre-equipped with save button (outside of the loaded form), which called the submit like this.
$modal.find("form.loaded_form").get(0).submit(); // INCORRECT
The former only executes raw submit, but:
$modal.find("form.loaded_form").trigger('submit'); // CORRECT
does the trick.