asp.net mvc case Tutorial (based on asp.net mvc beta)-Fifth: MVC integration Ajax

Source: Internet
Author: User

Summary

This article will start with the completion of the "Input data Validation" feature, and gradually expand the asp.net MVC and ajax approach. First, this article will use the synchronization method provided by ASP.net MVC to complete data validation. This functionality will then be asp.net into an asynchronous form, combined with Ajax and jquery, respectively.

Data validation

In the last article, we completed the announcement function. But from a robust standpoint, this feature is not perfect, because in general, we enter data to meet certain constraints, for example, in our example, we can at least the empty string as the title or content bar. Next, we'll add the data validation function to the program,

asp.net MVC provides good data validation implementation support, let's look at the implementation process here. First, we'll revise the release.aspx view, and the modified view is as follows.

Release.aspx:

1<%@ Page language= "C # autoeventwireup=" true "codebehind=" Release.aspx.cs "inherits=" MVCDemo.Views.Announce.Release "%>
2<%@ Import namespace=" MVCDemo.Models.Entities "%>
3
4<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ""
5
6 7 8 <title ></title>
9 10<body>
<% selectlist categories = viewdata["Categories"] as SelectList; %>
<div>
<H1>MVC Bulletin Publishing System-announcement <% html.beginform ("Dorelease", "Ann Ounce ", formmethod.post); %>
<dl>
<dt> title: </dt>
<dd><%= html.textbox ("title")%>& Lt;/dd>
<dd><%= html.validationmessage ("Titlevalidator")%></dd>
<dt> Class: </dt>
20 <dd><%= html.dropdownlist ("Category", categories)%></dd>
<dd></dd>
22 & Lt;dt> content: </dt>
<dd><%= Html.textarea ("content")%></dd>
= Html.validationmessage ("Contentvalidator")%></dd>
</dl>
<input type= "Submit" Val Ue= "Publish"/>
<% html.endform ();%>
</div>
29</body>
30

Related Article

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.