I’m a newbie about ASP.NET MVC 3, but I have a simple question.
Is it possible to call a Controller method from an CSHTML (Razor) page?
Example:
xxxControl.cs:
public String Bla(TestModel pModel)
{
return ...
}
index.cshtml:
@Bla(Model) <-- Error
Thanks.
Update:
Thanks @Nathan. This isn’t a good idea to do this on this way.
The goal is: I need some formatting string for a field of the Model. But where I put the code that return a formatting String in the case?
It is considered bad practice for a view to call methods located on a controller. Usually it is a controller action which populates a model and passes this model to the view. If you needed some formatting on this model you could write an HTML helper.
and in your view: