ASP. NET MVC2 in action Reading Notes [12-4] MVC Ajax helpers

Source: Internet
Author: User

Index. aspx:

 
<Script SRC= ".../Scripts/jquery-1.3.2.js" Type= "Text/JavaScript"> </Script>
 
<SCRIPT src =".../Scripts/microsoftajax. js"Type ="Text/JavaScript"> </SCRIPT>
 
 
 
<SCRIPT src =".../Scripts/microsoftmvcajax. js"Type ="Text/JavaScript"></Script>
 
 
 
 
<H3>Ajax. beginform</H3>
 
 
 
<H4>Comments</H4>
 
<Ul ID= "Comments">
 
</Ul>
 
 
<% Using(Ajax. beginform ("Addcomment",NewAjaxoptions
 
{
 
Httpmethod ="Post",
 
Updatetargetid ="Comments",
 
Insertionmode = insertionmode. insertafter
 
})){%>
 
 
<%= Html. textarea ("Comment",New{Rows = 5, cols = 50 })%>
 
<Button Type= "Submit">Add Comment</Button>
 
 
 
<%}%>
 
 
 
<H3>Ajax. Link</H3>
 
 
<%= Ajax. actionlink ("Show the Privacy Policy","Privacypolicy",
 
NewAjaxoptions {insertionmode = insertionmode. Replace, updatetargetid ="Privacy"})%>
 
 
 
<Div ID= "Privacy"> </Div>

 

Ajaxhelperscontroller. CS:

 
Public ClassAjaxhelperscontroller: Controller
 
{
PrivateIlist <String> _ Comments =NewList <String> ();
 
 
 
PublicActionresult index ()
 
{
 
ReturnView (_ Comments );
 
}
 
 
 
[Httppost]
 
PublicActionresult addcomment (StringComment)
 
{
 
_ Comments. Add ("<Li>"+ Comment +"</LI>");
ReturnContent (String. Join ("\ N", _ Comments. toarray ()));
 
}
 
 
 
PublicActionresult privacypolicy ()
 
{
 
Const StringPrivacytext =@"
 
<H2> our commitment to privacy </H2>
 
Your privacy is important to us. To better protect your privacy we provide this notice explaining our online
 
Information practices and the choices you can make about the way your information is collected and used.
To make this notice easy to find, we make it available on our homepage and at every point where personally
 
Identifiable information may be requested .";
 
 
 
ReturnContent (privacytext,"Text/html");
 
}
 
}

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.