HTML5¼¼Êõ

²»ÓÃasp.net MVC£¬ÓÃWebFormÕÕÑù¿ÉÒÔʵÏÖMVC£¨Çë¿´×îºóÒ»¾ä»°£© - ÑîÖпÆ(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-12-25 14:27 ÎÒÒªÆÀÂÛ( )

context.Server.TransferÊÇÔÚ·þÎñÆ÷ÄÚ²¿°ÑÇëÇó´¦ÀíȨת½»¸ø"PersonsView.aspx"´¦Àí¡£HttpContextÖеÄItemsµÄÉúÃüÖÜÆÚÊÇÕû¸öÇëÇóÏìÓ¦£¬ÕâÑùÎÒÃÇÔÚÒ»°ã´¦Àí³ÌÐòÖаÑÊý¾Ý·Åµ½context.ItemsÖУ¬È»ºóÔÚ"PersonsView.aspx

     context.Server.TransferÊÇÔÚ·þÎñÆ÷ÄÚ²¿°ÑÇëÇó´¦ÀíȨת½»¸ø"PersonsView.aspx"´¦Àí¡£HttpContextÖеÄItemsµÄÉúÃüÖÜÆÚÊÇÕû¸öÇëÇóÏìÓ¦£¬ÕâÑùÎÒÃÇÔÚÒ»°ã´¦Àí³ÌÐòÖаÑÊý¾Ý·Åµ½context.ItemsÖУ¬È»ºóÔÚ"PersonsView.aspx"ÖоͿÉÒÔ¿ÉÒÔͨ¹ýContext.Items["persons"]Äõ½Õâ¸öÊý¾Ý´Ó¶ø½øÐÐÊý¾ÝµÄչʾ¡£

     ÎªÊ²Ã´°ÑÊý¾Ý·Åµ½HttpContext.ItemsÖÐÄØ¡£ÓÉÓÚTransfer½ö½öÊÇ·þÎñÆ÷ÄÚ²¿´¦ÀíȨµÄת½Ó£¬µ«ÊÇÈÔÈ»ÊÇÔÚÒ»¸öÇëÇóÖеģ¬ËùÒԷŵ½Context.itemsÊÇ×îºÃµÄ¡£Èç¹û·Åµ½Session¡¢ApplicationµÈÖлáÓв¢·¢µÄÎÊÌâ¡£ 

    ÕâÑùController£¨Ò»°ã´¦Àí³ÌÐò£©ºÍView£¨aspx£©Ö®¼äֻҪά³ÖÒ»¸ö“Òª´«µÝÒ»¸öÃû×ÖΪpersonsÀàÐ͵ÄList<Person>”ÕâÑùÒ»¸öÈõñîºÏ¹Øϵ¼´¿É£¬ÖÁÓÚaspxÓò»ÓÃÕâ¸öpersons¡¢Óü¸´Îpersons¡¢ÔõôÓÃpersons£¬ÄãController¶¼²»Óùܡ£ 

°´ÕÕͬÑù·½·¨¸ÄÔì¼Ó·¨¼ÆËãÆ÷

 

ÏÂÃæÊÇÊÓͼAddView.aspxµÄ´úÂë

¼Ó·¨¼ÆËãÆ÷+

¶øAddHandler.ashxµÄÖ÷Ìå´úÂëÈçÏ£º

public void ProcessRequest(HttpContext context) { ]; dynamic viewBag = new System.Dynamic.ExpandoObject(); if(string.IsNullOrEmpty(action)) { viewBag.i1 = ""; viewBag.i2 = ""; viewBag.i3 = ""; } ) { ]); ]); int i3 = i1 + i2; viewBag.i1 = i1; viewBag.i2 = i2; viewBag.i3 = i3; } context.Items[] = viewBag; context.Server.Transfer(); }

 

    ÓÉÓÚViewºÍControllerÖ®¼ä´«µÝµÄÊý¾Ý±È½Ï¸´ÔÓ¡¢±È½Ï¶à£¬ÎªÁ˼ò»¯¿ª·¢£¬ÕâÑùÓÃÁËdynamic ¶¯Ì¬ÀàÐÍ¡£ÊìϤASP.Net MVCµÄͬѧÊDz»ÊǸоõÕâ¸öºÍASP.net MVCÖеÄViewBagÒìÇúͬ¹¤ÄØ¡£

    ÔÚÕâ¸ö¼Ó·¨¼ÆËãÆ÷ÖÐÈç¹ûÎÒÏë°Ñ½áËã½á¹ûÓÃspanÏÔʾ£¬ÄÇôֻҪ°Ñ<input type="text" name="i3" value="<%=viewBag.i3%>" />¸Ä³É<span><%=viewBag.i3%></span>¾Í¿ÉÒÔÁË¡£ÃÀ¹¤Ò²ÈÝÒ×½éÈëÒ³ÃæÃÀ»¯¡£

    Èç¹ûÎÒÏë°ÑÒ³ÃæµÄTitle´Ó“¼Ó·¨¼ÆËãÆ÷”¸Ä³É“3ºÍ5Ïà¼ÓµÄ½á¹û”£¬ÄÇôֻҪÕâÑù¸Ä¾Í¿ÉÒÔ£º<title><%=viewBag.i1 %>ºÍ<%=viewBag.i2 %>Ïà¼ÓµÄ½á¹û</title>    ÕâÑùmodelÀïµÄÊý¾ÝÎÒaspxÏëÓü¸´ÎÓü¸´Î£¬ÏëÔõôÓþÍÔõôÓá£ÓÐûÓиоõµ½ºÍWebForm²»Ò»ÑùµÄµØ·½ÄØ£¿

 

   ËùÒÔֻҪ˼ÏëÏëͨÁË£¬ÆäʵʵÏÖMVCģʽ²»Ò»¶¨ÒªÓÃASP.net MVC£¬ÎÒ¼û¹ýºÜ¶àÏîÄ¿¶¼ÊÇ×Ô¼º¸ãµÄMVC»úÖÆ¡£

    µ±È»¼ÈÈ»ASP.net MVCÒѾ­ÕâôÓÅÐãÁË£¬Ò»°ãÇé¿öû±ØÒªÏñÎÒÕâÑùÖØÐÂ×Ô¼º·¢Ã÷Ò»¸öÂÖ×ÓÓᣠ

    ÕâÀï¸ø´ó¼Ò½²ASPXʵÏÖMVCÖ»ÊÇÓôó¼ÒÊìϤµÄ¶«Î÷Èôó¼ÒÃ÷°×Ô­Àí£¬¹¤³ÌÏîÄ¿Ó¦Óû¹ÊÇÖ±½ÓÓÃASP.Net MVC°É¡£

   

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ÈçºÎÔÚ ASP.NET Core Öз¢ËÍÓʼþ - Savorboard

    ÈçºÎÔÚ ASP.NET Core Öз¢ËÍÓʼþ - Savorboard

    2017-05-02 08:02

  • Ê®¶þ¸ö ASP.NET Core Àý×Ó - Savorboard

    Ê®¶þ¸ö ASP.NET Core Àý×Ó - Savorboard

    2017-04-27 16:01

  • ASP.NET MVC5ÇëÇó¹ÜµÀºÍÉúÃüÖÜÆÚ - Ñ©·Éºè

    ASP.NET MVC5ÇëÇó¹ÜµÀºÍÉúÃüÖÜÆÚ - Ñ©·Éºè

    2017-04-24 08:04

  • ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄ¼¤»î - Savorboard

    ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄ¼¤»î - Savorboard

    2017-04-14 13:04

ÍøÓѵãÆÀ
«