How to redirect to Index from another controller?
Use the overloads that take the controller name too...
return RedirectToAction("Index", "MyController");
and
@Html.ActionLink("Link Name","Index", "MyController", null, null)
Redirect to Action in another controller
You can supply the area
in the routeValues
parameter. Try this:
return RedirectToAction("LogIn", "Account", new { area = "Admin" });
Or
return RedirectToAction("LogIn", "Account", new { area = "" });
depending on which area you're aiming for.
MVC Redirect to a different view in another controller
You can't do it the way you are doing it. You are trying to pass a complex object in the url, and that just doesn't work. The best way to do this is using route values, but that requires you to build the route values specifically. Because of all this work, and the fact that the route values will be shown on the URL, you probably want this to be as simple a concise as possible. I suggest only passing the ID to the object, which you would then use to look up the object in the target action method.
For instance:
return RedirectToAction("Edit", new {id = clientViewRecord.client.ClientId});
The above assumes you at using standard MVC routing that takes an id parameter. and that client is a complex object and not just the id, in which case you'd just use id = clientViewRecord.client
Asp.Net MVC - using RedirectToAction() to go to another controller in a different folder - 2 deep
According to Microsoft documentation, There is a process call View Discovery that search the Views automatically or by specifying the path :
To do this, I think, you have two solutions:
1 - Create Admin folder under the Views, and not under Views/AdminFunctions. by using the below redirection :
1.1 - HomeController
public ActionResult Index()
{
return RedirectToAction("Index", "Admin");
}
1.2 - AdminController
public ActionResult Index()
{
return View();
}
2 - Keep the same hierarchy, and specify the path to locate Index
view for AdminController :
2.1 - HomeController
public ActionResult Index()
{
return RedirectToAction("Index", "Admin");
}
2.2 - AdminController
public ActionResult Index()
{
return View("/Views/AdminFunctions/Admin/Index.cshtml");
}
I hope this will help you fix the issue
Redirect in MVC controller to another controller not working
Try this-
return RedirectToAction("Index", "Error", new {
ErrorTitle = "Record not Found",
ErrorMessage = "The Product you are looking for is no longer available"
});
You basically need to redirect to the error controller and pass in the params as part of the route. RedirectToAction takes a parameter of RouteValues
Also you do not need "ErrorController", you can just use "Error"
Redirecting to Another Controller
Switch the s
and profile
, you have them reversed. RedirectToAction
Asp.net MVC redirect Url to another controller view
Don't use Redirect to redirect to Actions in your app. There are several reasons for this. First, it's just simpler to user RedirectToAction as Alundra's answer provides. However, simpler is only part of the answer.
There's a problem with using Redirect. And that has to do with the way Routing works in MVC. In MVC, you can reach the same action via multiple different URL's. For instance, in a default MVC template, the following are all valid URL's.
http://yoursite/
http://yoursite/Home
http://yoursite/Home/Index
Now, what happens when you use Redirect? If you use the last url, it will work fine. You'll end up with the following url.
http://yoursite/Home/HomeMgr?Section=home&Type=Mgr
But if you're at any of the others, you have a problem...
http://yoursite/HomeMgr?Section=home&Type=Mgr
Oops... that won't work... That will be looking for a controller named HomeMgrController.
You get the same at the root as well.
Using RedirectToAction solves this problem, as it takes your routing into account and will figure out the correct url to redirect you to based on the Controller and Action you specify.
Redirect user from controller to another view MVC
You don't redirect to a view, you redirect to an action or a route. If I'm correctly parsing the path you're attempting, where you have this:
return Redirect("/Admin/Reporting/ReportManagement")
should be
return RedirectToAction("Reporting", "ReportManagement", new { area="Admin" })
This assumes a Reporting action on a ReportManagementController class in the Admin area.
Related Topics
How to Count Number of Visitors for Website in ASP.NET C#
How to Add/Update Child Entities When Updating a Parent Entity in Ef
How to Get Only Date from a Datetime Value in Razor Page
What Regular Expression Would I Use to Remove Everything After the Second Backslash
How to Loop Through All Fields in an Object in C#
Map a Property to List of Object Using Automapper Createmap
How to Cast Object to List<Object> and Turn It into an Array
Reading Only Specific Columns from a CSV File Out of Many
How to Hide a Property in Webapi
Entity Framework Core With Multiple Foreign Key on Same Column
How to Get the List of Properties of a Class
How to Generate Unique Number of 8 Digits
Formatting Date in Linq-To-Entities Query Causes Exception
How to Determine If .Net Core Is Installed
Linq to SQL Left Outer Join Using Lambda Syntax and Joining on 2 Columns (Composite Join Key)
How to Redirect to Login Page If Session Is Not Available in MVC
Generate Xml for <Govtalkmessage Xmlns="Http://Www.Govtalk.Gov.Uk/Cm/Envelope">