📜  redirecttoaction 不发送 id (1)

📅  最后修改于: 2023-12-03 15:34:41.733000             🧑  作者: Mango

Redirecting to Action without Sending ID

When working with ASP.NET MVC, it is often required to redirect to a different action in the controller without sending any IDs. This can be achieved using the RedirectToAction method.

Syntax
public RedirectToActionResult RedirectToAction(string actionName, string controllerName);
Example

In the following example, we have a HomeController with two actions, Index and About. We want to redirect from the Index action to the About action without sending any IDs.

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return RedirectToAction("About");
    }

    public IActionResult About()
    {
        return View();
    }
}

In the above code, when the Index action is called, it redirects to the About action using the RedirectToAction method. No IDs are sent in this redirect.

Markdown Code Snippet
# Redirecting to Action without Sending ID

When working with ASP.NET MVC, it is often required to redirect to a different action in the controller without sending any IDs. This can be achieved using the `RedirectToAction` method.

## Syntax

```csharp
public RedirectToActionResult RedirectToAction(string actionName, string controllerName);
Example

In the following example, we have a HomeController with two actions, Index and About. We want to redirect from the Index action to the About action without sending any IDs.

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return RedirectToAction("About");
    }

    public IActionResult About()
    {
        return View();
    }
}

In the above code, when the Index action is called, it redirects to the About action using the RedirectToAction method. No IDs are sent in this redirect.