How to call another controller Action From a controller in Mvc
Controllers are just classes - new one up and call the action method just like you would any other class member:
var result = new ControllerB().FileUploadMsgView("some string");
How to call a function written in one controller from another controller in mvc
You can solve this with inheritence.
Example:
public abstract class BaseController : Controller
{
//Common functionality between controllers go here
protected static string Encrypt(string toEncrypt, bool useHashing)
{
//Your content
}
}
public class LoginController : BaseController //not Controller anymore
{
//Encrypt is now available
//...Your controller methods here
}
public class RegisterController : BaseController //not Controller anymore
{
//Encrypt is now available
//...Your controller methods here
}
.NET MVC - Call a controller Action from another controller action
Controller.RedirectToAction
Can we call the Method of a controller from another controller in asp.net MVC?
You could also simply redirect straight to the method like so:
public class ThisController
{
public ActionResult Index()
{
return RedirectToAction("OtherMethod", "OtherController");
}
}
calling different Action Method from another Controller
If the method of StudentController
is named GetStudent
, then it needs to be
@Html.ActionLink("Get Student Info", "GetStudent", "Student")
The 2nd parameter is the name of the method your calling.
Related Topics
How to Provide Success Messages ASP.NET MVC
C# - How to Loop Through a Table to Update Each Row MySQL
How to Convert a Dictionary to a Json String in C#
Use Linq to Collaps Multiply Collections into One Collection
How to Get Cookies Info Inside of a Cookiecontainer (All of Them, Not for a Specific Domain)
How to Read/Write Files in .Net Core
Decrypt M3U8 Playlist Encrypted With Aes-128 Without Iv
Display Label Text With Line Breaks in C#
Filtering Out Values from a C# Generic Dictionary
How to Make Blazor Http Get Json Async Request
C# Double - Tostring() Formatting With Two Decimal Places But No Rounding
C# Adding Multiple Items to List
How to Rename Keys Within a Json File
C# Windows Form Application for Employee Management
Javascript - How to Set Values to Session in JavaScript
C# ASP.NET MVC Download a File Via Ajax
How to Print the Elements With Text Value That Contains in a List Selenium C#
Could Not Parse the Json File ,Error in Progam.Cs ASP.NET Core