DataAnnotations with html submit form - asp.net-mvc-4

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?

Related

Asp.Net Core, Loading partial view in to a form and trying to get not the list of the model on form submit

Asp.Net Core, Loading partial view into a form and trying to get not the list of the model on form submit,
So i have a with some rows of data. i have a button add to the from so if you need more lines which is currently been loading in my ajax. but im not able to get the infomation from the feilds loading in the form from the ajax append.

How do I submit a form to an MVC controller action using a blazor EditForm component?

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?

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.

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.