熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.Net環境下基於Ajax的MVC方案[2]

2022-06-13   來源: .NET編程 
      部分范例源碼

  Defaultaspx

<%@ Page language=c# Codebehind=Defaultaspxcs AutoEventWireup=false Inherits=CNTeddyAjaxHelperWebForm %>
<!DOCTYPE HTML PUBLIC //WC//DTD HTML  Transitional//EN >
<HTML>
    <HEAD>
        <title>WebForm</title>
        <meta name=GENERATOR Content=Microsoft Visual Studio NET >
        <meta name=CODE_LANGUAGE Content=C#>
        <meta name=vs_defaultClientScript content=JavaScript>
        <meta name=vs_targetSchema content=http://schemasmicrosoftcom/intellisense/ie>
        <script type=text/javascript language=javascript src=js/AjaxHelperjs></script>
    </HEAD>
    <body>
        <form id=Form method=post runat=server>
            <div id=view>loading</div>
            <script type=text/javascript>
                Updater(AjaxTemplate/GetPageSrc view url=http://wwwcnblogscom);
            </script>

        
</form>
    </body>
</HTML>

AjaxHelperjs摘要

var AjaxHelperUrl = new String(Ajaxaspx);



var Updater = function
(ajaxTemplate output params onComplete)

{

    if (typeof output ==
 string)

    {

        output =
 $(output);

    }

    

    new AjaxRequest( Ajaxaspx { onComplete: function(transport) { if (output != null) { outputinnerHTML = FormatContent(transportresponseText); } if (onComplete != null) { onComplete(FormatContent(transportresponseText)) } } parameters: params + &AjaxTemplate= +
 ajaxTemplate });

}



var SerializeForm = function
(form)

{

    return
 Formserialize(form);

}



var FormatContent = function
(str)

{

    var content = new
 String(str);

    var prefix = new String(<!AjaxContent>
);

    content = contentsubstring(contentindexOf(prefix ) + prefixlength contentlength  
);

    return
 content;

}

UserControl GetPageSrcascxcs摘要

        private void Page_Load(object sender SystemEventArgs e)
        
{
            lbUrlText = RequestForm[url
];

            SystemNetWebClient client = new
 SystemNetWebClient ();
            clientHeadersAdd(UserAgent Mozilla/ (compatible; MSIE ; Windows NT NET CLR )
);
            try

            {
                txtPageSourceText = new
 SystemIOStreamReader(clientOpenRead(lbUrlText) SystemTextEncodingUTF)ReadToEnd();
            }

            catch(Exception ex)
            
{
                
throw ex;
            }

        }

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15431.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.