1. Create a model: Member. CS in the models folder.
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. web; </P> <p> namespace mvcapplication2.models <br/> {<br/> public class member <br/>{< br/> // <summary> <br/> /// attributes of the model, the name does not need to correspond to the database field, but it must be the same as the database field for ease of reading. <Br/> // </Summary> <br/> Public string name {Get; Set ;}</P> <p> Public String age {Get; set ;} </P> <p> Public String sex {Get; Set ;}< br/>}< br/>}
Member can be created in accountmodel. CS in the default models, or a class file. The code above creates a new file,
2. Create another action: memberindex ()
If the newly created class file is in the original Mo file, memberindex should also be created in the corresponding controller. If it is a newly created class file, create the action in the corresponding controller as follows:
Public actionresult memberindex () <br/>{< br/> mvcapplication2.models. member M = new mvcapplication2.models. member (); <br/> M. name = "James"; <br/> M. sex = "male"; <br/> M. age = "24"; <br/> return view (m); <br/>}
3. Create a view page file for the action:
1. Name: Same as memberindex and action
Generate the page after adding:
<Fieldset>
<Legend> fields </legend>
<Div class = "display-label"> name: <% = html. encode (model. Name) %> </div>
<Div class = "display-field"> </div>
<Div class = "display-label"> Age: <% = html. encode (model. Age) %> </div>
<Div class = "display-field"> </div>
<Div class = "display-label"> sex: <% = html. encode (model. Sex) %> </div>
<Div class = "display-field"> </div>
</Fieldset>
<P>
<% = Html. actionlink ("edit", "edit", new {/* id = model. primarykey */}) %> |
<% = Html. actionlink ("back to list", "Index") %>
</P>
Run, http: // localhost: 4116/admin/memberindex
Next article: Asp.net MVC three actionresult returns other values