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