Asp.net MVC learning diary 12 (powerful mvccontrib, automatically generating HTML elements)

Source: Internet
Author: User

1. Renewal. (Pay attention to version issues)

Of course nbuilder. dll is also required (if you don't know what it is, check the previous one or Google it, huh, huh)

2. Drag all the aspx pages under the inputbuildertemplates folder in mvccontrib to your project views> shared

3. Create examplemodel and exampletypes.

Public class examplemodel
{
Public guid key {Get; set ;}
[Required]
Public String firstname {Get; set ;}
[Required]
Public String lastname {Get; set ;}
[Required]
[Label ("What type of example is this? ")]
Public exampletypes exampletype {Get; set ;}
[Label ("Please enter your birthday")]
[Example ("mm/DD/YYYY")]
Public datetime birthdate {Get; set ;}
[Datatype (datatype. multilinetext)]
Public String biography {Get; set ;}
}

Public Enum exampletypes
{
Man = 1,
Woman = 2,
Boy = 3,
Girl = 4,
Baby = 5
}

4. Add

Public actionresult showexample ()
{
Examplemodel model = builder <examplemodel>
. Createnew ()
. Build ();
Return view (model );
}

5. Add in Web. config

......

<Add namespace = "mvccontrib. UI"/>
<Add namespace = "mvccontrib. UI. inputbuilder. Views"/>

</Namespaces>
</Pages>

6. Do not forget to add JS references to site. master.

<SCRIPT src = ".../scripts/jquery-1.4.1.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = ".../scripts/jquery-ui.js" type = "text/JavaScript"> </SCRIPT>

7. Add a strong showexample View

<Fieldset>
<Legend> fields </legend>

<% Html. beginform (); %>
<% = Html. Input (M => M. Key) %>
<% = Html. Input (M => M. firstname) %>
<% = Html. Input (M => M. lastname) %>
<% = Html. Input (M => M. exampletype) %>
<% = Html. Input (M => M. Birthdate) %>
<% = Html. Input (M => M. Biography) %>
<Div style = "clear: Both;">
<Input type = "Submit" value = "Submit"/> </div>
<% Html. endform (); %>
</Fieldset>

This is already very simple. You don't need to write too much code, do you? I have tried many open-source resources such as Asp.net MVC. It seems that foreign experts like MVC.

 

Let's take a look at the more concise:

Add new action and view

Public actionresult new ()
{
Return view (New examplemodel ());
}

Add in newview

<% = Html. inputform () %>

OK. Is this more awesome?

 

 

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.