ASP.NET MVC ÈëÃÅ6¡¢TempData
ASP.NET
MVCµÄTempDataÓÃÓÚ´«ÊäһЩÁÙʱµÄÊý¾Ý£¬ÀýÈçÔÚ¸÷¸ö¿ØÖÆÆ÷Action¼ä´«µÝÁÙʱµÄÊý¾Ý»òÕ߸øView´«µÝһЩÁÙʱµÄÊý¾Ý£¬ÏàÐÅ´ó¼Ò¶¼¿´¹ý“ÔÚ
ASP.NETÒ³Ãæ¼ä´«ÖµµÄ·½·¨ÓÐÄļ¸ÖÖ”Õâ¸öÃæÊÔÌ⣬ÔÚASP.NET
MVCÖÐTempDataµÄ¾ÍÊÇÆäÖеÄÒ»ÖÖ´«Öµ·½·¨¡£TempDataĬÈÏÊÇʹÓÃSessionÀ´´æ´¢ÁÙʱÊý¾ÝµÄ£¬TempDataÖдæ·ÅµÄÊý¾ÝÖ»Ò»´Î·Ã
ÎÊÖÐÓÐЧ£¬Ò»´Î·ÃÎÊÍêºó¾Í»áɾ³ýÁ˵ġ£Õâ¸öÒ»´Î·ÃÎÊÖ¸µÄÊÇÒ»¸öÇëÇóµ½ÏÂÒ»¸öÇëÇó£¬ÒòΪÔÚÏÂÒ»¸öÇëÇóµ½À´Ö®ºó£¬»á´ÓSessionÖÐÈ¡³ö±£´æÔÚÀïÃæµÄ
TempDataÊý¾Ý²¢¸³Öµ¸øTempData£¬È»ºó½«Êý¾Ý´ÓSessionÖÐɾ³ý¡£ÎÒÃÇ¿´Ò»ÏÂASP.NET MVC Preview5Ô´Â룺
Ò²¾ÍÊÇ˵TempDataÖ»±£´æµ½ÏÂÒ»¸öÇëÇóÖУ¬ÏÂÒ»¸öÇëÇóÍêÁËÖ®ºó£¬TempData¾Í»á±»É¾³ýÁË¡£×¢ÒâÕâÀïTempDataʹÓÃSession
À´×ö´æ´¢µÄ£¬SessionÊǶÔÓ¦Ìض¨Óû§µÄ£¬ËùÒÔ²¢²»´æÔÚ²¢·¢ÎÊÌâ¡£Èç¹ûÄãÓÃÊý¾Ý¿âÀ´×öTempDataµÄ´æ´¢½éÖʵĻ°£¬±ØÐëÒª¿¼ÂÇÕâ¸öÇé¿öµÄ¡£ÖÁÓÚÈç
ºÎ×Ô¶¨ÒåTempDataµÄ´æ´¢½éÖÊ£¬Äã¿ÉÒԲο¼“ASP.NET MVC:
ÓÃdb4oÀ´×öTempDataProvider(Áí¸½Ò»¸ö·ºÐ͵ÄRedirectToAction·½·¨)
”ÕâһƪÎÄÕ¡£
Ç°Ãæ˵µ½µÄÔÚÎÒÃǵÄBaseControllerÖÐÓÐÒ»¸öÏÔʾÌáʾÐÅÏ¢¸øÓû§µÄ·½·¨£¬Õâ¸öÌáʾÐÅÏ¢¾ÍÊÇÁÙʱµÄÐÅÏ¢£¬ÎÒÃÇ¿ÉÒÔʹÓÃTempDataÀ´
ʵÏÖ¡£ÏÂÃæÈÃÎÒÃÇÀ´ÊµÏÖÕâ¸öÌáʾÐÅÏ¢µÄ·½·¨£º
protected
ActionResult ShowMsg(List
<
string
>
msgs)
{
TempData[
"
Messages
"
]
=
msgs;
return
RedirectToAction(
"
Message
"
);
}
public
ActionResult Message()
{
return
View(TempData[
"
Messages
"
]
as
List
<
string
>
);
}
ÒòΪÎÒÃǵÄController¶¼¼Ì³Ð×ÔÕâ¸öÎÒÃÇ×Ô¶¨ÒåµÄBaseController£¬ËùÒÔÎÒô¿ÉÒÔ²ÅControllerÖÐÕâÑùÀ´¸øÓû§ÏÔʾÌá
ʾÐÅÏ¢£º
Ïà¹ØÎĵµ£º
ÔÚ×öasp.netµÄWeb¿ª·¢µÄʱºò£¬ÎÒÃǾ³£»áÓöµ½Ò»´ÎÐÔÉÏ´«¶à¸öÎļþµÄÐèÇó¡£Í¨³£ÎÒÃǵĽâ¾ö·½·¨Êǹ̶¨·Å¶à¸öÉÏ´«Îļþ¿ò£¬ÕâÑùµÄ½â¾ö°ì·¨ÏÔÈ»ÊDz»ºÏÀíµÄ£¬ÒòΪһ´ÎÉÏ´«¶à¸ö£¬¾ÍÒâζ×ÅÊýÁ¿²»È·¶¨¡£Òò´ËÎÒÃǾÍÒªÈÃÕâЩÎļþÉÏ´«¿ò¶¯Ì¬Ìí¼Ó£¬ÏÂÃæÎÒÒÔÎÒ×öµÄÒ»¸öͼ¿â¹ÜÀíÖеÄÉÏ´«Í¼Æ¬µÄ¹¦ÄÜΪÀý
ÏÈ¿´Ð§¹û£º
´ò¿ªµÄ³õʼ½çÃ棺
ĬÈÏ ......
ÔÚASPÖУ¬½«ÎļþÉÏ´«µ½·þÎñÆ÷ÊÇÒ»¼þ·Ç³£Âé·³µÄÊÂÇ飬ͨ³£ÐèÒªµÚÈý·½×é¼þµÄÖ§³Ö¡£
ÔÚASP.NET 1.x ÖУ¬ÒªÖ§³ÖÎļþÉÏ´«£¬Ö»ÐëʹÓÃHTMLµÄInput(File)¿Ø¼þ¡£°ÑËü×÷Ϊ·þÎñÆ÷¿Ø¼þÔËÐУ¨ÊÖ¶¯ÉèÖÃrunat="server"£© £¬ÒªÖ±½Ó²Ù×÷ HttpPostedFile¡£
ÔÚASP.NET 2.0ÖУ¬ÐÂÔöÁËFileUpLoad·þÎñÆ÷¿Ø¼þ£¬Ê¹µÃÉÏ´«¸ü¼Ó¼òµ¥¡£
°ü& ......
1. ͼƬÎÊÌâ
·Ç³£ºÃ½â¾ö
<img runat="server" src="~/images/ad468x60.gif" alt="" />
¼ÓÉÏrunat="server" £¬Â·¾¶Ê¹Óþø¶Ô·¾¶~/»ù±¾ÉϾÍOKÁË¡£
2. CSSÎļþÒýÓÃ
<link rel="stylesheet" type="text/css" href="style.css" />
ÕâÀïÉñÆæµÄ¾ÍÊÇlinkµÄÎļþµÄhrefÊÇËæ×ű»·ÃÎÊÎļþµÄĿ¼½á¹¹×Ô¶¯µ÷Õû£¬Ëµ°×Á˾ ......
//TransmitFileʵÏÖÏÂÔØ
protected void Button1_Click1(object sender, EventArgs e)
{
/*
&n ......
ASP.NET Excelµ¼Èëµ½SQL ServerÊý¾Ý¿â
Ìṩ°ÑExcelÀïµÄÊý¾Ýµ¼Èëµ½SQL Server Êý¾Ý¿â£¬Ç°ÌáÊÇExcelÀïµÄ×Ö¶ÎÔÚSql Server±íÀﶼÓУ¬²»È»»á³öÏÖ´íÎó¡£×¢ÊͺÜÏêϸŶ£¡ÒªÒýÓõÄÃüÃû¿Õ¼äÊÇ£º
using System.Data.OleDb;
using System.Data.SqlClient;
//²Ù×÷Àà
public class ExcelToSQL
{
& ......