asp.net mvc:model Binding to Simple Types, Complex Types,......

Source: Internet
Author: User

asp.net mvc:model Binding to Simple Types, Complex Types, collections, dictionaries, ETC

Environment:

Windows 2008, VS 2008 SP1, asp.net Mvc RC1

1. Simple Type

Here, we refer to the following book class as a simple type:

public class book

{public

int BookID {get; set;}

public string BookName {get; set;}

public string Author {get; set;}

Public DateTime publisheddate {get; set;}

}

Assuming that you now need to implement the Add book feature, the following action is defined in Bookcontroller:

[Acceptverbs (Httpverbs.post)]

Public ActionResult Create (book book) {

//to does

//insert book into Database

Return redirecttoaction ("Index");

}

The question now is how to name the textbox in view to achieve automatic binding, as follows:

<div>

<%using (Html.BeginForm ("Create", "book")} {%>

<div>

Book Name: <%=html.textbox ("BookName")%>

</div>

<div>

Author: <%= Html.textbox ("Author")%>

</div>

<div>

published Date: <%=html.te Xtbox ("Publisheddate")%>

</div>

<div>

<input type= "submit" ID = "Submit" Name= "submit" value= "Submit"/>

</div>

<%}%>

</div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.