1

I'm doing some web forms development after having developed using ASP MVC for a long time. Is there a way to databind the controls the way you do it in MVC? In MVC I'd have a model class and then bind the property to a control like this.

@model MyClass

@Html.TextboxFor(x => Model.Name)

However, in MVC when I use an it looks like I have to do the binding manually on the codebehind. Is there a way of declaring a model class for the page and then do something like this?

<asp:TextBox Text="<% Model.Name %>" />
paddingtonMike
  • 1,441
  • 1
  • 21
  • 37
  • I think this post will answer your question: http://stackoverflow.com/questions/5264852/can-we-use-razor-syntax-in-asp-net-webforms-aspx-pages – richb01 Apr 16 '14 at 11:22
  • Reading another post I can use <%# %> and then use the DataBind action of the Page in the codebehind to bind the value of a public property to that control. http://stackoverflow.com/questions/9595851/set-visible-property-with-server-tag-in-framework-3-5 – paddingtonMike Apr 16 '14 at 15:58
  • OK, I think I see what you are trying to do. Maybe even simpler than `<%# %>` could be to just declare your model class as `protected` in the code-behind. Protected variables are accessible from client code using `<%= %>` notation. – richb01 Apr 17 '14 at 17:33

0 Answers0