Skip to content
Advertisement

Value from form input does not be transmit by the submit button. How can I fix that?

i try to add fields in a form by clicking a button. The fields appear and the validation works either. The problem is, that the value of these input fields isn’t transmitted by the submit button of the form.

The framework is ASP.NET Core-Web-App (Model View Controller) with .Net 5.

I add the fields with the following code.

 putMoreFields.addEventListener("click", function () {
    
    myTextField.insertAdjacentHTML('afterend',
        '<label asp-for="ContactMail" class="form-label"></label> <input type="email" class="form-control" asp-for="ContactMail" placeholder="name@example.com" required> <span asp-validation-for="ContactMail" class="text-danger"></span> </div> <div class="invalid-feedback"> Bitte geben Sie eine Mail-Adresse ein. </div> </div >')
    myTextField.insertAdjacentHTML('afterend',
        '<label asp-for="ContactMail" class="form-label"></label> <input type="date" class="form-control" asp-for="ContactMail" placeholder="dd.mm.jjjj" required> <span asp-validation-for="ContactMail" class="text-danger"></span> </div> <div class="invalid-feedback"> Bitte geben Sie eine Mail-Adresse ein. </div> </div >')
    
})

Can someone help me?

Best regards

JuRi-2020

Advertisement

Answer

You just need change all the code

asp-for="ContactMail"

to

 name="ContacMail"
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement