主攻ASP.NET.4.5 MVC4.0之重生:可多选框数据存放
可多选框数据存放
Controller
1 public ActionResult SendInfo(SendInfo model, FormCollection fc, int[] GetSendInfo, int[] SetSendInfo) 2 { 3 int getsendinfoID = 0; 4 int setsendinfoID = 0; 5 foreach (int gsi in GetSendInfo) 6 { 7 switch (gsi) 8 { 9 case 0: getsendinfoID = getsendinfoID + 1; break; 10 case 1: getsendinfoID = getsendinfoID + 10; break; 11 case 2: getsendinfoID = getsendinfoID + 100; break; 12 case 3: getsendinfoID = getsendinfoID + 1000; break; 13 case 4: getsendinfoID = getsendinfoID + 10000; break; 14 } 15 } 16 17 foreach (int gsi in SetSendInfo) 18 { 19 switch (gsi) 20 { 21 case 0: setsendinfoID = setsendinfoID + 1; break; 22 case 1: setsendinfoID = setsendinfoID + 10; break; 23 case 2: setsendinfoID = setsendinfoID + 100; break; 24 case 3: setsendinfoID = setsendinfoID + 1000; break; 25 } 26 } 27 model.SetSendInfo = setsendinfoID; 28 model.GetSendInfo = getsendinfoID; 29 model.State = 1; 30 model.CreateTime = DateTime.Now; 31 sendinforepository.SaveOrEditModel(model); 32 return RedirectToAction("ysqgk"); 33 }
View
1 <TABLE width=100% border="0" cellPadding=6 cellSpacing=1> 2 <TBODY> 3 <TR align=middle> 4 <TD width="25%" height="30" class=maincol2_only_right 5 style='border-top:none'> 6 是否申请减免费用 7 </TD> 8 <TD class=maincol2_only_right noWrap width="33%"> 9 所需信息的指定提供方式(可多选) 10 <SPAN class=star>*</SPAN> 11 </TD> 12 <TD class=maincol2_only_right2 width="33%"> 13 获取信息的方式(可多选) 14 <SPAN class=star>*</SPAN> 15 </TD> 16 </TR> 17 <TR> 18 <TD class=inputcol_only_right vAlign=top> 19 <TABLE width="100%" cellPadding=3 cellSpacing=0 class=text-1> 20 <TBODY> 21 <TR> 22 <TD width=15> 23 <INPUT type=radio value="1" name="Expense" 24 id="Expense"> 25 </TD> 26 <TD class="left"> 27 申请。请提供相关证明 28 </TD> 29 </TR> 30 <TR> 31 <TD> 32 <INPUT type=radio CHECKED value="0" name="Expense" 33 id="Radio2"> 34 </TD> 35 <TD class="left"> 36 不 37 </TD> 38 </TR> 39 40 </TBODY> 41 </TABLE> 42 </TD> 43 <TD class=inputcol_only_right vAlign=top> 44 <TABLE class=text-1 cellSpacing=0 cellPadding=3 width="100%"> 45 <TBODY> 46 <TR> 47 <TD width=15> 48 <input id="tgfs" name="tgfs" type="hidden" value=""> 49 <INPUT name="SetSendInfo" type="checkbox" value="0"> 50 </TD> 51 <TD class="left"> 52 纸面 53 </TD> 54 </TR> 55 <TR> 56 <TD> 57 <INPUT name="SetSendInfo" type="checkbox" value="1"> 58 </TD> 59 <TD class="left"> 60 电子邮件 61 </TD> 62 </TR> 63 <TR> 64 <TD> 65 <INPUT name="SetSendInfo" type="checkbox" value="2"> 66 </TD> 67 <TD class="left"> 68 光盘 69 </TD> 70 </TR> 71 <TR> 72 <TD> 73 <INPUT name="SetSendInfo" type="checkbox" value="3"> 74 </TD> 75 <TD class="left"> 76 磁盘 77 </TD> 78 </TR> 79 </TBODY> 80 </TABLE> 81 </TD> 82 <TD class=inputcol vAlign=top> 83 <TABLE class=text-1 cellSpacing=0 cellPadding=3 width="100%"> 84 <TBODY> 85 <TR> 86 <TD width=15> 87 88 <INPUT type="checkbox" value="0" name="GetSendInfo"> 89 </TD> 90 <TD class="left"> 91 邮寄 92 </TD> 93 </TR> 94 <TR> 95 <TD> 96 <INPUT type="checkbox" value="1" name="GetSendInfo"> 97 </TD> 98 <TD class="left"> 99 快递 100 </TD> 101 </TR> 102 <TR> 103 <TD> 104 <INPUT type="checkbox" value="2" name="GetSendInfo"> 105 </TD> 106 <TD class="left"> 107 电子邮件 108 </TD> 109 </TR> 110 <TR> 111 <TD> 112 <INPUT type="checkbox" value="3" name="GetSendInfo"> 113 </TD> 114 <TD class="left"> 115 传真 116 </TD> 117 </TR> 118 <TR> 119 <TD> 120 <INPUT type="checkbox" value="4" name="GetSendInfo"> 121 </TD> 122 <TD class="left"> 123 自行领取/当场阅读、抄录 124 </TD> 125 </TR> 126 </TBODY> 127 </TABLE> 128 </TD> 129 </TR> 130 </TBODY> 131 </TABLE>
StringHelper
1 public static string Setsendinfo(int Num) 2 { 3 string number = ""; 4 switch (Num) 5 { 6 case 0: 7 number = "纸面"; 8 break; 9 case 1: 10 number = "电子邮件"; 11 break; 12 case 2: 13 number = "光盘"; 14 break; 15 case 3: 16 number = "磁盘"; 17 break; 18 } 19 return number.ToString(); 20 } 21 22 23 public static string Getsendinfo(int Num) 24 { 25 string number = ""; 26 switch (Num) 27 { 28 case 0: 29 number = "邮寄"; 30 break; 31 case 1: 32 number = "快递"; 33 break; 34 case 2: 35 number = "电子邮件"; 36 break; 37 case 3: 38 number = "传真"; 39 break; 40 case 4: 41 number = "自行领取/当场阅读、抄录"; 42 break; 43 } 44 return number.ToString(); 45 }
Detail
1 <p> 2 <b>所需信息的指定提供方式:</b> 3 <%var setsendinfo = Model.SetSendInfo.ToString().PadLeft(4, '0'); 4 5 char[] inca = setsendinfo.ToCharArray(); 6 string strtempa = "-"; 7 string strtempb = ""; 8 string setstrtemp = ""; 9 10 for (int sn = 0; sn < inca.Length; sn++) 11 { 12 if (inca[sn].ToString() == "1") 13 { 14 strtempa = Soft.Helpers.StringHelper.Setsendinfo(sn); 15 } 16 else 17 { 18 strtempa = "-"; 19 } 20 setstrtemp = setstrtemp + "-" + strtempa; 21 } 22 23 24 %> 25 <%= Html.Encode(setstrtemp) %> 26 </p> 27 28 <p> 29 <b>获取信息的方式:</b> 30 <%var getsendinfo = Model.GetSendInfo.ToString().PadLeft(4, '0'); 31 32 char[] incb = setsendinfo.ToCharArray(); 33 string strtempc = "-"; 34 string strtempd = ""; 35 string getstrtemp = ""; 36 for (int sn = 0; sn < incb.Length; sn++) 37 { 38 if (incb[sn].ToString() == "1") 39 { 40 strtempc = Soft.Helpers.StringHelper.Getsendinfo(sn); 41 } 42 else 43 { 44 strtempc = "-"; 45 } 46 getstrtemp = getstrtemp + "-" + strtempc; 47 } 48 49 %> 50 <%= Html.Encode(getstrtemp) %> 51 </p>
假设勾选
所需信息的指定提供方式格式:0101
获取信息的方式:10101
可多选:勾选:1,不勾选:0
数据库存放
查看方式