c# - Calling a method in the controller -


i'm newbie asp.net mvc 3, have simple question. possible call controller method cshtml (razor) page?

example:

xxxcontrol.cs:

public string bla(testmodel pmodel) {     return ... } 

index.cshtml:

@bla(model) <-- error 

thanks.

update:

thanks @nathan. isn't idea on way. goal is: need formatting string field of model. put code return formatting string in case?

it considered bad practice view call methods located on controller. controller action populates model , passes model view. if needed formatting on model write html helper.

public static class htmlextensions {     public static ihtmlstring bla(this htmlhelper<testmodel> htmlhelper)     {         testmodel model = htmlhelper.viewdata.model;         var value = string.format("bla bla {0}", model.someproperty);         return mvchtmlstring.create(value);     } } 

and in view:

@html.bla() 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -