0

I want to access page when user clicks to button.

By changing url, such as ..../Member/Batch/Create I want my site redirect user to another page.

How can I do this via ASP.NET Core MVC 3.1?

Subrato
  • 15
  • 4
  • Check this [Redirect to Action in another controller](https://stackoverflow.com/questions/10785245/redirect-to-action-in-another-controller/10785274) – Genusatplay Jun 06 '21 at 16:44

2 Answers2

1

Use:

<a href="@Url.Action("Batch", "Member", null)">Create Batch</a>

See this answer and help for more details.

Lovely
  • 306
  • 2
  • 12
0

Do you mean we could only access the controller by using button?

If this is your requirement, you could try to check the Request.Headers["Referer"].ToString() to make sure just which url could access this controller.

Like below:

    public IActionResult Privacy()
    {
        var re = Request.Headers["Referer"].ToString();
        if (Request.Headers["Referer"].ToString() != "https://localhost:44342/home/index")
        {
            return View("Error");
        }
        else
        {
            return View();
        }

    }

Result:

enter image description here

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65