Jack Peeterson
Jack Peeterson

Reputation: 35

Button type ="submit" also redirects to another page after submitting?

How can I make my button ""input type="submit" value="Create" class="btn btn-default" " also redirect to another page(View) after submitting? Basically, I made a simple Form which sends email after that button click, and automatically returns me to Index page (default controller option(asp.net mvc core)), and i want to redirect it to another "Thank you for submitting an email" page(View).

Upvotes: 2

Views: 1496

Answers (4)

noob0349
noob0349

Reputation: 1

you could use a return RedirectToPage("Thankyou");
as the return statement of your controller Action so that it redirects to a Thankyou.cshtml page.

Upvotes: 0

Rahul Singh Chauhan
Rahul Singh Chauhan

Reputation: 329

// in PHP you can use

redirect('thank-you.php'); 
or 
header('location:thank-you.php');

/* function for redirect index or home page after some time you can write a setTimeout function in thank-you page.*/

<script>
  $(function(){
   setTimeout(function(){ window.location.href = "index.php"; }, 3000);
});
</script>

// I hope this is work for you.

Upvotes: 2

Lorddirt
Lorddirt

Reputation: 470

You forgot to add action='index.php' to your form tag.

e.g.

<form action='index.php'>
<input type='submit'/>
</form>

which gives a 404 error, because theres no such page as index.php

Upvotes: 2

Syed Khizaruddin
Syed Khizaruddin

Reputation: 435

use action attribute inside form element that will redirect you to the page where you want it to be,

just you need to give the link or directory of that file or page or if you have created routing, then give route path according to the framework you are using this will help you for clear understanding

<form action="another_page.php"> <input type="text"> <button type="submit"> </form>

Upvotes: 1

Related Questions