I want to call a non-action method in a view. Can I do that? In other words, there is a method in my controller which returns a string. I want to call that method in my view (.cshtml) and show it in the view. All I could see was, the methods should return an ActionResult. But in my case I do not need a view returned just a string.
Asp.net-mvc – Calling non-Action methods from view-MVC .NET
asp.net-mvcasp.net-mvc-4
Related Topic
- Javascript – ASP.NET MVC JsonResult Date Format
- Asp.net-mvc – Display a view from another controller in ASP.NET MVC
- Asp.net-mvc – Must ASP.NET MVC Controller Methods Return ActionResult
- C# – ASP.NET MVC ambiguous action methods
- Asp.net-mvc – How to get MVC action to return 404
- C# – ASP.Net MVC: Calling a method from a view
- Relink a shared library to a different version of libc
Best Answer
The best way (and MVC convention way) to do this is to use a
ViewModel
. Quick example:Model
Controller
View
Hope that helps!