Forms in Modal Bootstrap

Asked

Viewed 63 times

-1

I’m with a system that all forms (Views) are in Modal Bootstrap.

The View Index loads all Partialview. Below the Index:

inserir a descrição da imagem aqui

By clicking the Register button, for example, a Javascript function accesses Action Create via AJAX, and this in turn returns to Parialview '_Create':

Javascript:

JS

Action:

C#

The modal with the registration form is loaded on the screen:

modal create

When submitting the form by clicking Save, an internal check is made if the name already exists:

Create post

In a normal, static form, this would work beauty. But in this case Partialview is returned as a static page, and without Layout:

partial

Someone has come across this scenario and could help me?

  • You are submitting the page from a form on the page or via jquery with ajax?

  • From a form, button Submit. I thought of creating an ajax method to verify the existence first, and according to the return submit the form. But it’s another thing I don’t know yet how it works. Submit the form in Javascript.

2 answers

0

I did it. You have to do everything in Javascript. I don’t know if my code offers the best solution, but it was like this:

First, in the controller I separated the function verifying the existence of the entity, so that it could make the verification before submitting the form:

controller

Then I changed the Submit button that submitted the form to the Controller, leaving it as type button, calling a Javascript (Cratebanco) function, as below:

inserir a descrição da imagem aqui

Note that there are two Javascript functions. The first verifies the existence of the object, and according to the result triggers or not the 'Submitter' function. This function performs the Submit event, sending the data to Action Create, which persists the data.

0

This way I keep the Modal Bootstrap open while checking the existence of the typed data. And I can provide the answer to the user about this condition, before the data persists.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.