2

I was wondering if there was a way to bind the value of an input field straight to the property in the Model through a strongly typed model. For example, let's say my Model is an Address object. I want to be able to say Html.Textbox(Model.Address1.State, "state", Model.Address1.State). So the first parameter would be the explicit property I want to bind to of the model with the value from the user, the second parameter would just be the DOM id, and the third value would be the initial value to input when I render the view.

I know you can do Html.TextBox("Address.State") and have a custom binder which would create the Address object for you and populate the state property. I need Html.Textbox(Model.Address1.State).

Help?

3
  • Are you asking to do something like: <%= Html.TextBoxFor(model => model.EmailAddress) %> Commented Dec 1, 2009 at 21:54
  • Yes, precisely. I keep seeing Html.TextBoxFor. Where is this from? Commented Dec 1, 2009 at 22:01
  • MVC 2.0 (currently in Beta) haacked.com/archive/2009/11/17/asp.net-mvc-2-beta-released.aspx Commented Dec 1, 2009 at 22:04

1 Answer 1

2

I think the FluentHtml stuff from the mvccontrib code is what you may want to check out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.