New to programming - Currently working on a project for my Apprenticeship. I have a setup a asp.net application in Visual Studio. I have added a controller and created a 'contact' page. This works fine, user input is sent to the database no problems so far. The next step for me is to improve the UI so I have written the following Jquery code:
$(document).ready(function () {
$("#show").hide();
$("#click").click(function () {
$("#hide").hide();
$("#show").toggle();
return false;
});
});
This hides the div containing the input fields and submit button (for the contact page) and shows a div with a 'thank you' message. This function does hide the div but this stops the user input from being sent to the database.
Here is the C# code from the controller:
public async Task<IActionResult> Create([Bind("Id,FullName,EmailAddress,Message")] Contact contact)
{
if (ModelState.IsValid)
{
_context.Add(contact);
await _context.SaveChangesAsync();
}
return View(contact);
}
The 'return false' in the JQuery script seems to be the problem but if I 'return true' then the script doesn't work (unless there isn't any input within the fields).
My question is how can I get both the script and the back end to work at the same time?
Hope this makes sense and apologies if I haven't provided enough info
Thanks