English 中文(简体)
Creating and Simple Class and Calling a Method from a cshtml File
原标题:

Could some one give a simple example of creating a simple class with a simple method and calling the method from cshtml file in webmatrix?

I am trying to figure out if WebMatrix could be used in an object oriented way that would allow me to take advantage of the razor sytax as a view engine alternative to the MVC framework that I could use in combination with webforms applications. Having the power and productivity of webforms on the back-end and razor on the public facing pages would be really awesome.

I have very limited knowledge of asp.net but WebMatrix intrigues me but I don t think the full inline approach is the right way to go.

Thank you!

最佳回答

Just put a .cs file in App_Code with something like this...

public class Something {
    public void DoIt() {
    }
}

Then in a .cshtml file just call...

var something = new Something();
something.DoIt();

You could also just make it static and call Something.DoIt directly.

Hope that helps.

问题回答

暂无回答




相关问题
How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

ASP.NET MVC Razor view engine

After reading Scott Guthrie s blog entry about the new Razor view engine for ASP.NET MVC and reading this question comparing the available view engines. Razor seems to address most of the problems ...

Client Id for Property (ASP.Net MVC)

I m trying to do a label for a TextBox in my View and I d like to know, how can I take a Id that will be render in client to generate scripts... for example: <label for="<%=x.Name.ClientId%>"...

Get Current Area Name in View or Controller

How do you get the current area name in the view or controller? Is there anything like ViewContext.RouteData.Values["controller"] for areas?

MVC which submit button has been pressed

I have two buttons on my MVC form: <input name="submit" type="submit" id="submit" value="Save" /> <input name="process" type="submit" id="process" value="Process" /> From my Controller ...

热门标签