Could you tell me a way(s) that I can bind a model property to a html-element, created without using html helper?
In other words to a plain html element such as: <input type="text" />
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are referring to Model Binding, it does not require helpers, but naming convention. Helpers just make it easy and concise to create the HTML markup.
You could create plain HTML inputs and just set the
nameattribute correctly. The default naming convention is just dot based, omitting the parent level entity’s name, but qualifying it from there.Consider this controller:
And this model:
You could create the following form purely in HTML:
If you want to display the posted values (in the second
Submitoverload), your HTML will have to be modified render the model properties. You’d place this in a view, in this case using Razor syntax and calledSubmit.cshtml:So, this can be done without helpers, but you’d want to use them as much as possible.