Reputation: 11
I am currently working on updating an old page to the new Razor syntax and was hoping I can just recycle the majority of the code-behind functions I already have from my old code. With asp tags, writing something similar to
<asp:Textbox ID="txtcust" runat="server">
would allow me to access txtcust as a variable in my code-behind for the page to get/set the data within the textbox. Is there something similarly simple I can do with the new Razor syntax?
Upvotes: 1
Views: 1930
Reputation: 7200
Although they both are built on top of the ASP.NET framework, MVC and WebForms really do not share much in common. MVC works off of Models, Views and Controllers, which does not really translate (directly) to the WebForms structure of code-behinds and server controls. My suggestion would be to review the MVC tutorials and just start building your site from scratch until you gain a full understanding of how you can map the WebForms structures over to MVC. It is not straightforward, but with some time and patience it can be done.
http://www.asp.net/mvc/tutorials
Upvotes: 0
Reputation: 141
You could use TextBoxFor and bind the textbox to the model (this is one of the perks of MVC and Razor syntax).
@Html.TextBoxFor(model => model.Property)
Then in your controller you can manipulate the model values so they are reflected in your View automatically. This is essentially the way you do it in MVC as opposed to stinky Web Forms.
Hope this helps!
Upvotes: 1
Reputation: 22984
If you want to use helpers to create HTML controls (bearing in mind that you aren't going to "interact" with them in a codebehind like you would in WebForms), you can use:
@Html.TextBox()
Upvotes: 0
Reputation: 887453
You're fundamentally misunderstanding MVC.
MVC works with models, not controls.
Upvotes: 3